Reputation: 152
I have a list view which is inflated with a linear layout containing six text view. I want the width of inflated text view to be match parent but its width is getting set according to value I am getting from database(Getting wrapped). I have given equal weights to textview in linear layout but width of all the textviews are different. Values of text view are coming from database using JDBC connection.
List view layout is:
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<ListView
android:id="@+id/lv"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:divider="#0dcd6600"
android:dividerHeight="2dp" >
</ListView>
</HorizontalScrollView>
And that of row inflated in list view is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#ffffff"
android:orientation="horizontal"
android:weightSum="6" >
<TextView
android:id="@+id/txt_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/border1"
android:padding="7dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="@+id/txt_sname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/border1"
android:padding="7dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="@+id/txt_standard"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/border1"
android:padding="7dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="@+id/txt_division"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/border1"
android:padding="7dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="@+id/txt_grno"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/border1"
android:padding="7dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<TextView
android:id="@+id/txt_rollno"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/border1"
android:padding="7dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
So far I have tried all the below options, nothing worked.
Here is the image of the layout which is not proper. Text fields are not getting aligned.
And how I want it to be is like this.
Upvotes: 0
Views: 531
Reputation: 949
This is happening due to listview in HorizontalScrollView. Weightsum and weight does not work if list view is in horizontal scroll view..
Upvotes: 1
Reputation: 2912
It's not a solution but i think you are wrong here. Don't use scrollview as a parent. Please try this once. Hope it will work.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" >
<ListView
android:id="@+id/lv"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
</ListView>
</HorizontalScrollView>
</LinearLayout>
Upvotes: 0