ListView layout_weight not working, height set to 0dp

ぐ巨炮叔叔 提交于 2019-12-10 17:16:40

问题


I'm trying to use the layout_weight attribute for testing. It works fine excpect for the ListView. I've set the height to 0dp and the weightsum. I've tried to put the ListView into 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 this is how it looks:

It seems connected to the theme I'm using. I'm using Theme.Black.NoTitleBar Theme. The weird thing is I can see it normal 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 I'm rarly coding in XML. Is there a fix for this? Is this a known bug?


回答1:


You can change the Theme of the IDE in the right top border. It may be that the current theme chosen miss some attrs.



来源:https://stackoverflow.com/questions/21313240/listview-layout-weight-not-working-height-set-to-0dp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!