Reputation: 11
I'm sure it must be a little issue but I'm not able to make it work. I had a xml with two columns (weights: 5 & 1 as you can see in the table.xml) that worked perfectly. Now, I have add another one with the header and the data is not being placed in two columns with the weights as before and it is being placed all together, except for the header that works fine.
I do not want to put fix width values so I'd like a solution with the weight way.
Here are the two xml I'm using:
header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/header"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<!-- Header -->
<LinearLayout android:background="#1d688f"
android:paddingTop="6dip"
android:paddingBottom="6dip"
android:paddingLeft="6dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView
android:id="@+id/pid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:id="@+id/paiseur"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="20sp"
android:text="@string/pais"/>
<TextView
android:id="@+id/cantidadeur"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textStyle="bold"
android:gravity="center"
android:textSize="20sp"
android:text="@string/total" />
</LinearLayout>
<!-- List Divider -->
<View android:layout_width="fill_parent"
android:layout_height="5dip"
android:background="?android:attr/listDivider" />
<!-- ListView (grid_items) -->
<LinearLayout android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="6">
<ListView android:id="@android:id/list"
android:layout_height="fill_parent"
android:layout_width="0dp"
android:layout_weight="6">
</ListView>
</LinearLayout>
</LinearLayout>
And the one for the list, table.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="6dip"
android:paddingBottom="6dip"
android:paddingLeft="6dip"
android:layout_weight="6"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/pid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:id="@+id/paiseur"
android:layout_width="fill_parent"
android:layout_weight="5"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="20sp" />
<TextView
android:id="@+id/cantidadeur"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textStyle="bold"
android:gravity="center"
android:textSize="20sp" />
</LinearLayout>
I have tried to change the width to 220dp of paiseseur in the table.xml and it indeed separate the coulmns but I'd like to have with weight as in the header.
I add the code just in case it has something to do:
setContentView(R.layout.header);
ListView lv = (ListView) findViewById(android.R.id.list);
SimpleAdapter adapter = new SimpleAdapter(
Verpaiseur.this, paisesList,
R.layout.table, new String[]{TAG_PID, TAG_PAIS, TAG_TOTAL},
new int[]{R.id.pid, R.id.paiseur, R.id.cantidadeur});
lv.setAdapter(adapter);
Thank you very much!
Upvotes: 1
Views: 85
Reputation: 22965
try this one , as you have not given orientation to layout it cause error,
without using weightSum
you will not get proper solution and if you get that than it will not be applicable to all other devices.
header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<!-- Header -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#1d688f"
android:orientation="horizontal"
android:paddingBottom="6dip"
android:paddingLeft="6dip"
android:paddingTop="6dip"
android:weightSum="7">
<TextView
android:id="@+id/pid"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="visible" />
<TextView
android:id="@+id/paiseur"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="pais"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/cantidadeur"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="total"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<!-- List Divider -->
<View
android:layout_width="fill_parent"
android:layout_height="5dip"
android:background="?android:attr/listDivider" />
<!-- ListView (grid_items) -->
<LinearLayout
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="6">
<ListView
android:id="@android:id/list"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="6"></ListView>
</LinearLayout>
</LinearLayout>
table.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5dp"
android:orientation="horizontal"
android:weightSum="7">
<TextView
android:id="@+id/pid"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="1"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="visible" />
<TextView
android:id="@+id/paiseur"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:gravity="center"
android:text="paiseur"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/cantidadeur"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="cantidadeur"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
Upvotes: 0
Reputation: 33438
You've not set the width to 0dp at all places where you've used weight. Sometimes this causes garbage output in layouts if missed. Try setting width to 0dp every where you've used weight and see if that fixes your problem.
One example where you've not done it is this:
<!-- ListView (grid_items) -->
<LinearLayout android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="6">
Check if the same thing is there else where.
Upvotes: 0
Reputation: 322
try this. This will help you.
<LinearLayout android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="6">
<ListView android:id="@android:id/list"
android:layout_height="fill_parent"
android:layout_width="match_parent">
</ListView>
Upvotes: 1