change the width of linear layout in android
android, android-layout
Solution
make changes in listview like shown below, do hard code for layout width in XML.
<?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="vertical" android:background="@android:color/white">
<ListView
android:id="@+id/list"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#2f4f4f" >
</ListView>
</LinearLayout>
you were doing Wrap_content in linear layout and in listview fill_parent, therefore linearlayout which is wrapping listview i.e. full screen.
Problem
I am having this xml layout for a list view : ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/menu" android:orientation="vertical" android:background="#2f4f4f" android:layout_width="wrap_content" android:layout_height="fill_parent"> <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#2f4f4f" android:cacheColorHint="#2f4f4f" android:scrollbars="none"> </ListView> </LinearLayout> ``` The linear layout occupies the full screen width by default. I want to change it programatically.I want to make something like this : But when I change width of linearlayout nothing happens,it still occupies full screen width ``` LayoutInflater inflater = LayoutInflater.from(this); View menu = inflater.inflate(R.layout.xml_layout, null); menu.setLayoutParams(new LayoutParams(20,LayoutParams.WRAP_CONTENT)); ``` after hardcoding layout width in list view as : ``` <ListView android:id="@+id/list" android:layout_width="200dp" android:layout_height="wrap_content" android:background="#2f4f4f" android:cacheColorHint="#2f4f4f" android:scrollbars="none" > </ListView> ``` I get this : Please suggest a way to do this.