Reputation: 26387
My listview is set as:
<ListView
android:id="@+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/border"
android:padding="5dp">
</ListView>
I load items based on the xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/topbar"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_margin="0px"
android:orientation="horizontal"
android:padding="0dp" >
<TextView
android:id="@+id/place"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="0px"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textSize="40sp" />
<LinearLayout
android:id="@+id/right"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="0px"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="25sp" >
<TextView
android:id="@+id/score"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:gravity="center"
android:textAlignment="viewEnd"
android:textSize="25sp" />
<LinearLayout
android:id="@+id/bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:textSize="25sp" >
<TextView
android:id="@+id/time"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp" />
<TextView
android:id="@+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
For some reason the line android:layout_height="200dp"
has no effect. Regardless whether I write 200dp or 20dp android shows the same item height.
What do I have to change to get the item height that I want?
Upvotes: 0
Views: 576
Reputation: 2969
Your LinearLayout
with id of topbar two main childs those are a TextView
with id of place and a LinearLayout
with id of right. You did not set any height values on this childs. They are set as wrap_content
. So they will extend with respect to content. If your content is short, they will not extend to 200dp.
layout_height
as
fill_parent
,layout_weight
usage on LinearLayout
. Check Linear Layout and weight in Android .Good luck.
Upvotes: 0
Reputation: 39836
a View
only have LayoutParam
if it's inside a layout.
The moment you inflate a view without a parent layout, any XML layout_
attribute is ignored.
So to answer the question, you have to inflate the view with the parent, like this:
public View getView (int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView =
LayoutInflater.from(parent.getContext())
.inflate(R.layout.layout_name, parent, false);
}
}
Upvotes: 1