Two ListViews on the side

I have two ListViews. And I need to place them side by side horizontally. But the problem is that only one list is visible. (Note: the second list is on the right side of the layout and can have no more than 1 character. And the first list will expand to fill the rest of the screen.)

Help me please.

The layout is as follows.

------------ | | | | | | | | | | | | | | | | | | | | | | | | | | | ------------ 

 <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="vertical" > <ListView android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:layout_width="fill_parent" android:layout_height="fill_parent" android:drawSelectorOnTop="true" /> </LinearLayout> 

Shaiful

+8
android listview
source share
8 answers

I think using this code will work fine. You should use layout_weight = 0.5 and everything will work just fine.

 <LinearLayout android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_marginBottom="60dp" android:layout_marginTop="60dp" android:orientation="horizontal" android:id="@+id/linearLayout2"> <ListView android:id="@+id/sportsList" android:layout_width="match_parent" android:layout_height="wrap_content" android:entries="@array/sports_array" android:layout_weight="0.5"/> <ListView android:id="@+id/sportsList_1" android:layout_width="match_parent" android:layout_height="wrap_content" android:entries="@array/sports_array" android:layout_weight="0.5"/> </LinearLayout> 

So basically use two kinds of list in a linear layout and give each layout a weight of 0.5. I think this helps.

+8
source share

I canโ€™t believe that no one came up with this after three years. Maybe someone else will have this question.

The problem is that ListView is greedy when it comes to horizontal space. You can say that it works using layout_width='0dp' and any layout_weight numbers you think are best. The following is an example of placing leftListView at ยพ and rightListView at ยผ. I tried, it works great.

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <ListView android:id="@+id/leftListView" android:layout_width="0dp" android:layout_height="match_parent" android:layout_margin="2dp" android:layout_weight=".75" /> <ListView android:id="@+id/rightListView" android:layout_width="0dp" android:layout_height="match_parent" android:layout_margin="2dp" android:layout_weight=".25" /> </LinearLayout> 

Another alternative is the same trick with layout, but with FrameLayouts, and then create snippets for each ListView. It's harder, but you can find value in the Fragments around.

+4
source share

I would suggest LinearLayout with the android:orientation="horizontal" attribute android:orientation="horizontal"
Then put 2 LinearLayouts with android:orientation="vertical" in horizontal.
Now fill the vertical with one of your material.

See here for more details :)

Hope this helps!

EDIT:
Try the following:

 <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="75dp"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1"> **YOUR STUFF** </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> android:layout_weight="2"> **YOUR STUFF** </LinearLayout> </LinearLayout> 
+1
source share

Your first LinearLayout says fill_parent both in height and in width, so it will occupy the entire room. Instead, use one LinearLayout, which is set to horizontal, and then place two ListViews in it. Height should be wrap_content. Width can be set, but you want (but not fill_parent), and you can use minWidth and layout_weight to better indicate.

+1
source share

Try using a relative layout or table layout as the root layout, and then position 2 lists as children of the root.

0
source share

Put these two in a horizontal LinearLayout, as some have suggested. For the list on the left, set layout_width to 0 and layout_weight to 1; for the list on the right, set layout_width to wrap_content and layout_weight to 0.

0
source share
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <ListView android:id="@+id/list_view2" android:layout_width="100dp" android:layout_height="475dp" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" /> <ListView android:id="@+id/list_view" android:layout_width="306dp" android:layout_height="match_parent" android:layout_alignParentEnd`enter code here`="true" android:layout_alignParentRight="true" /> </LinearLayout> 
0
source share

Ok I see that the stream is dead, but I know how to do it.

My xml file layout:

 <?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="fill_parent" android:orientation="horizontal" > <RelativeLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" > <RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="55dp" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" > </RelativeLayout> <ListView android:id="@+id/ListView01" android:layout_width="192px" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_toRightOf="@+id/relativeLayout1" android:layout_weight="1" > </ListView> </RelativeLayout> <RelativeLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" > <RelativeLayout android:id="@+id/relativeLayout2" android:layout_width="55dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_alignParentTop="true" > </RelativeLayout> <ListView android:id="@+id/ListView02" android:layout_width="192px" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_toLeftOf="@+id/relativeLayout2" android:layout_weight="1" > </ListView> </RelativeLayout> </LinearLayout> 

My second code is from activity:

  @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setContentView(R.layout.main); ListView lv1=(ListView)this.findViewById(R.id.ListView01); ListView lv2=(ListView)this.findViewById(R.id.ListView02); File fCurrDirOne = new File ("/"); File fCurrDirTwo = new File ("/"); String[] mListOfFilesOne = fCurrDirOne.list(); String[] mListOfFilesTwo = fCurrDirTwo.list(); ArrayAdapter list1 = new ArrayAdapter<String>( this, R.layout.itemlistview,mListOfFilesOne); ArrayAdapter list2 = new ArrayAdapter<String>( this, R.layout.itemlistview,mListOfFilesTwo); lv1.setAdapter(list1); lv2.setAdapter(list2); } 

Enjoy)

PS you have to create layuot for your list items, my called itemlistview.xml, and you can use android.R.layout.simple_list_item_1 by default.

Itemlistview.xml file

 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="20dp" > </TextView> 
-one
source share

All Articles