android, cannot align icons on the right in listview's row
I am currently working on my first android app. In a listview, I need to have the following organisation in each row:
- On the left: one main icon on which takes the whole height of the row
- On the middle: 2 texts, one below the other
- On the right: 2 icons, one below the other
I end up with a row.xml file like this, but that does not work as I expect. Do you know if something obvious is missing in this file ? Thanks a lot, Luc
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<ImageView
android:id="@+id/icon"
android:layout_width="48px"
android:layout_height="48px"
android:layout_marginRight="0dip"
android:src="@drawable/icon" />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="16dp"
android:textStyle="bold"
android:text="TITLE"
android:paddingLeft="5dp"
/>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="14dp"
android:text="DESCRIPTION"
android:paddingLeft="5dp"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="right">
<ImageButton
android:id="@+id/button_modify"
android:layout_width="16px"
android:layout_height="16px"
android:src="@drawable/deleteicon"
/>
<ImageButton
android:id="@+id/button_delete"
android:layout_width="16px"
android:layout_height="16px"
android:src="@drawable/modifyicon"
/>
</LinearLayout>
Asked by: Tess837 | Posted: 20-01-2022
Answer 1
In the right-hand-column LinearLayout
, add
android:layout_width="wrap_content"
android:gravity="right"
That should make the icons should fall to the right (because of the gravity
setting.)
Answer 2
Consider switching to RelativeLayout
for a rule set like you describe. Using LinearLayouts
may not work in all cases and will be less efficient than the RelativeLayout
in terms of stack consumption.
Similar questions
java - Save a custom ListView's instance state?
I have a custom ListView that uses a custom ArrayAdapter (which basically just overrides getView()). This custom adapter uses as its backend a List<CustomObject>. The elements in this List are retrieved from the network, so I would like to save it in onSaveInstanceState(). However, I can't find a way to put a List<E> in a...
android - I want to start new Activity when i click on ListView's content
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
Intent i = new Intent(this, contents.class);
startActivityForResult(i, 1);
But when i click on ListView it encounters en error. Tell me where i m wrong????
android - Call to ListView's setEmpty method not working (nothing is displayed when the list is empty)
I have an Activity which contains a ListView defined in XML (its not subclassing the ListActivity class).
I want to display a message when the ListView is empty, so I tried doing so with the setEmptyView method:
listView = (ListView) findViewById(R.id.list);
TextView emptyListText = new TextView(this);
// also tried with the following line uncommented
// emptyListText.setId(android.R.id.empty);
empt...
android - ListView's contents scrambled on scroll
So I am having a problem with the different pieces of that make up my ListView. I put them into an ArrayList and use a custom ArrayAdapter to hook up to the ListView, which I have done before so I don't believe there is a problem there. Initially the list seems to have the pieces in the correct order, but then I will scroll down the list and the contents will then load in incorrect order. I then scroll back up and everythi...
android - Change ListView's textcolor
I am trying to change the text color of the ListView but I cant find how to do that..<
listViewObject= (ListView) findViewById(R.id.chathlist);
ArrayList<String> chatHistory = new ArrayList<String>();
chatHistory.add("Msg 1");
chatHistory.add("Msg 2");
chatHistory.add("Msg 3");
chatHistory.add("Msg 4");
chatHistory.add("Msg 5")...
android - How to call a class on listview's item
Hi I am creating an application in which i am showing a list view on click of a tab button.
I want to know how to call a class after clicking an item in list
android - How do I set an empty ListView's background image?
How yo set listview background like this.
I want to appear when the number of record 0
java - Android: JSON and ListView's quickest refresh options?
I have the following class:
public class RandomDrunkQuotes extends Activity {
/** Called when the activity is first created. */
TextView txt;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i("uDrew Debug", "Made it into onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("uDrew Debug", "main Layout Loaded");
//Add AdMob viewer
A...
android - How to return a listview's scrollbar back to top, after changing data on adapter?
I'm using a ViewFlipper with 2 ListViews: one for categories, and one for data.
Every time user picks a category - i update the 2nd listview's data (clear it and add new data), call notifydatachanged, and call the ViewFlipper showNext().
The problem is that when i scroll down in a list, and than go back (showprev) to pick another category, and again flip to the updated list - the scrollbar is where i've left him, i...
Android:About listview's item color
I add a listview and add some textview into it.
In the listview's OnItemCLickListener I wanna change the textColor , then problems come:When I change the text color by setTextColor(Color.BLACK) ,the item will change to black;But when I change the color by setTextColor(R.color.mycolor) , all the items' color will change ! I cannot understand why?
Is there any way to solve this problem?...
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android