Android的 - 在同一条线上的两个按钮灌装的整个宽度线上、宽度、同一条、按钮

2023-09-05 08:39:42 作者:她夏了夏天

我有一个小问题定义一个相对布局。我有一个列表视图与滚动和两个按钮总是在列表视图的底部可见。我只是希望我的两个按钮有宽度的50%,填充线。这是我的code:

 < XML版本=1.0编码=UTF-8&GT?;

< RelativeLayout的
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=垂直>

    <按钮
        机器人:ID =@ + ID / testbutton
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:文本=保存/>

    <按钮
        机器人:ID =@ + ID / cancelButton
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:layout_toRightOf =@ + ID / testbutton
        机器人:文本=取消/>

    < ListView的机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:ID =@ + ID / LstPeriodOptions
        机器人:layout_alignParentTop =真
        机器人:layout_above =@ ID / testbutton/>

< / RelativeLayout的>
 

我试图引入在一个线性布局按钮和得到比重= 1与宽度= 0dp但在这种情况下,在ListView自败。你能帮助我吗?

对不起,我的英语水平。这是结果,我想有:

感谢了很多,最诚挚的问候。

编辑:这是我试着用线性布局:

 < XML版本=1.0编码=UTF-8&GT?;

< RelativeLayout的
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=垂直>

    <的LinearLayout
       机器人:layout_width =WRAP_CONTENT
       机器人:layout_height =WRAP_CONTENT
       机器人:ID =@ + ID /容器>

        <按钮
            机器人:ID =@ + ID / testbutton
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentBottom =真
            机器人:文本=和保存/>

        <按钮
            机器人:ID =@ + ID / cancelButton
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentBottom =真
            机器人:layout_toRightOf =@ + ID / testbutton
            机器人:文本=Cancelar/>
    < / LinearLayout中>

    < ListView的机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:ID =@ + ID / LstPeriodOptions
        机器人:layout_alignParentTop =真
        机器人:layout_above =@ ID /容器/>

< / RelativeLayout的>
 

解决方案

你有没有以这种方式尝试用你的的LinearLayout ,因为这应该工作。注意:所有的属性更改。因为我不知道你怎么了,我不能点出所有的差异。

 < XML版本=1.0编码=UTF-8&GT?;

< RelativeLayout的
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>
   <的LinearLayout
      机器人:ID =@ + ID / btnLL
      机器人:layout_width =match_parent
      机器人:layout_height =WRAP_CONTENT
      机器人:layout_alignParentBottom =真正的>
    <按钮
        机器人:ID =@ + ID / testbutton
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:文本=保存/>

    <按钮
        机器人:ID =@ + ID / cancelButton
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:文本=取消/>
  < / LinearLayout中>
    < ListView的机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
        机器人:ID =@ + ID / LstPeriodOptions
        机器人:layout_above =@ ID / btnLL/>

< / RelativeLayout的>
 
Android改变按钮的点击区域

I have a little problem defining a Relative Layout. I have a List View with scroll and two buttons always visible at the bottom of the list view. I just would like my two button have 50% of the width, filling the line. This is my code:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:orientation="vertical" >

    <Button 
        android:id="@+id/testbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Save" />

    <Button
        android:id="@+id/cancelButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" 
        android:layout_toRightOf="@+id/testbutton"
        android:text="Cancel"/>

    <ListView android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:id="@+id/LstPeriodOptions"
        android:layout_alignParentTop="true" 
        android:layout_above="@id/testbutton" />

</RelativeLayout>

I tried to introduce the buttons in a Linear Layout and give the gravity=1 with width=0dp but in that case the ListView dissapears. Could you help me please?

Sorry for my english. This is the result I would like to have:

Thanks a lot, best regards.

EDIT: This is what I tried with Linear Layout:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:orientation="vertical" >

    <LinearLayout 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/container" >

        <Button 
            android:id="@+id/testbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="Guardar" />

        <Button
            android:id="@+id/cancelButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true" 
            android:layout_toRightOf="@+id/testbutton"
            android:text="Cancelar"/>
    </LinearLayout>

    <ListView android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:id="@+id/LstPeriodOptions"
        android:layout_alignParentTop="true" 
        android:layout_above="@id/container" />

</RelativeLayout>

解决方案

Did you try with your LinearLayout in this way because this should work. Note all of the property changes. Since I don't know how yours was, I can't point out all of the differences.

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
   <LinearLayout
      android:id="@+id/btnLL"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true">
    <Button 
        android:id="@+id/testbutton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Save" />

    <Button
        android:id="@+id/cancelButton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Cancel"/>
  </LinearLayout>
    <ListView android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:id="@+id/LstPeriodOptions"
        android:layout_above="@id/btnLL" />

</RelativeLayout>

 
精彩推荐
图片推荐