ListView layout_weight not working, height set to 0dp

I am trying to use the layout_weight attribute for testing. This works great except for ListView. I set 0dp height and weight. I tried to put the ListView in a relative layout, but I get the same result.

Here is my code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.25"
    android:text="TextView" />

<ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.25" >
</ListView>

<TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.25"
    android:text="TextView" />

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.25"
    android:text="Button" />

</LinearLayout>

And here is what it looks like:

pic

This seems to be related to the theme I'm using. I am using Theme.Black.NoTitleBarTheme. The strange thing is that I see this normally in the emulator, but not in the IDE, but I need to see things in the IDE, because I work a lot with the GUI and very rarely code in XML. Can this be fixed? Is this a known bug?

+4
1

IDE . , .

0

Source: https://habr.com/ru/post/1523380/


All Articles