如何使用android:layout_weight和listview

如何使用android:layout_weight和listview,android,listview,Android,Listview,我想基于android:layout\u weight设置UI 一切正常,但当我们设置ListView id时,它会显示所有布局。因此,请任何人帮助我解决这个问题。谢谢将您的列表视图放在线性布局中并给出布局_weight=“50”到线性布局。然后将列表视图的宽度和高度设置为填充父级 同样给线性布局layout height=“0dp”把你的列表视图放在线性布局内,给线性布局赋予布局

我想基于android:layout\u weight设置UI



一切正常,但当我们设置ListView id时,它会显示所有布局。因此,请任何人帮助我解决这个问题。谢谢

将您的
列表视图
放在
线性布局中
并给出
布局_weight=“50”
线性布局
。然后将
列表视图
的宽度和高度设置为
填充父级


同样给线性布局
layout height=“0dp”

把你的
列表视图
放在
线性布局
内,给
线性布局
赋予
布局
。然后让
列表视图的宽度和高度填充父视图


同时给出线性布局
layout height=“0dp”

您需要如下更改xml:

//alter both LinearLayout as
android:layout_weight="25"
android:layout_height="0dp"

//alter ListView as
android:layout_weight="50"
android:layout_height="0dp"
android:isScrollContainer="false"

您需要按如下方式更改xml:

//alter both LinearLayout as
android:layout_weight="25"
android:layout_height="0dp"

//alter ListView as
android:layout_weight="50"
android:layout_height="0dp"
android:isScrollContainer="false"




我使用了这个,但如果我不使用android:id,则没有效果,然后工作,但当我使用id时,则出现了此问题您是否在emulator或真实设备上测试了它?我使用了这个,但如果我不使用android:id,则没有效果,然后工作,但当我使用id时,则出现了此问题您是否在emulator或真实设备上测试了它?如果您正在设置listview的android:layout\u weight=“50”则应将其高度设置为“0px”,以便将其设置为父视图的50%。如果您设置listview的android:layout\u weight=“50”,则应将其高度设置为“0px”,以便将其设置为父视图的50%。同样的问题,先生,我不知道为什么会出现此问题,从逻辑上讲,不应出现此问题,实际上是什么?listview或按钮容器?stretch mean layout fit automatically没有android的影响:layout\u weight。如果你粘贴上面的代码,它就可以正常工作。我试过用removin标签。另外,请告诉我你是如何在没有提供idyeah的情况下访问视图的@Hitesh Jain你是对的,实际上当我填充值时,它会拉伸,我错了,timesame问题,先生,我不知道为什么会发生这个问题,从逻辑上讲,这不应该发生,实际上是什么拉伸?listview或按钮容器?stretch mean layout fit automatically没有android的影响:layout\u weight。如果你粘贴上面的代码,它就可以正常工作。我试过用removin标签。另外,请告诉我,你是如何在没有提供idyeah的情况下访问视图的@Hitesh Jain,你是对的,事实上,当我填充值时,它会延伸,当时我错了
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="25"
    android:orientation="horizontal" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="25"
    android:orientation="horizontal" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />
</LinearLayout>

<ListView
    android:id="@+id/relatedContent"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_marginBottom="60dp"
    android:layout_weight="50"
    android:cacheColorHint="@android:color/transparent" >
</ListView>