How To Use Percenrelativelayout For Listview Item
Solution 1:
I have opened this issue to google. The answer were
The height of your ListView row item is insufficiently specified.
The first child says it wants to take 60% of the row height (note that this is heightPercent and not aspectRatio), and the second child says it wants to take 10% of the row height. But nothing tells ListView how tall the entire row wants to be. So it ends up being with height 0.
Note that the semantics of height=match_parent do not work in ListView rows, and if this works in any one particular Android platform version (for however much you can say it works), it is purely incidental.
Solution 2:
I encountered the same problem with android K and android L.
The percent layout won't work correctly before android M. The reason is that they depend on the size hint being delivered in the measuring step. Before android M most layouts would provide size hint 0.
Convert your percent relative layout to relative layout and set the height of the views programmatically according to your device height.
This is not a very elegant solution but it worked for me.
XML Code:
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><ImageViewandroid:id="@+id/test_image_id"android:layout_width="match_parent"android:layout_height="300dp"android:background="#d20404" /><TextViewandroid:id="@+id/textview"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_below="@+id/test_image_id"android:background="#000"android:text="sfgfashdsfg" /></RelativeLayout>
Java Code:
// to get the height of the screenint height = getWindowManager().getDefaultDisplay().getHeight();
// to set height to each textview to 50% of screen
textView1.getLayoutParams().height = (int) (height * 0.50);
Post a Comment for "How To Use Percenrelativelayout For Listview Item"