Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 两个线性布局中尺寸相同的按钮_Android_Xml_Android Layout_Layout_Android Linearlayout - Fatal编程技术网

Android 两个线性布局中尺寸相同的按钮

Android 两个线性布局中尺寸相同的按钮,android,xml,android-layout,layout,android-linearlayout,Android,Xml,Android Layout,Layout,Android Linearlayout,我的Android应用程序中有两个LinearLayouts。一个(顶部)有一个文本视图和一个按钮,下面的一个有两个按钮s。我想知道是否有办法使上部LinearLayout的右按钮与底部LinearLayout的右按钮大小相同 <LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout1" android:layout_height="wrap_content" andro

我的
Android
应用程序中有两个
LinearLayout
s。一个(顶部)有一个
文本视图
和一个
按钮
,下面的一个有两个
按钮
s。我想知道是否有办法使上部
LinearLayout
的右按钮与底部
LinearLayout
的右按钮大小相同

<LinearLayout android:layout_width="fill_parent"
     android:id="@+id/linearLayout1" android:layout_height="wrap_content"
     android:orientation="horizontal" android:paddingTop="15.0dip">

     <TextView 
          android:paddingLeft="5.0dip" 
          android:textSize="33px"
          android:textStyle="bold" 
          android:layout_height="wrap_content"
          android:id="@+id/textViewPoints" 
          android:text="Points: 0"
          android:layout_width="wrap_content" 
          android:layout_gravity="center_vertical"
          android:paddingRight="25.0dip" 
          android:layout_weight="0" />

     <Button 
          android:enabled="false" 
          android:onClick="myClickHandler"
          android:layout_height="wrap_content" 
          android:id="@+id/buttonAddTracker"
          android:layout_width="fill_parent"  
          android:layout_gravity="center_vertical"
          android:text="@string/buttonAddTracker" 
          android:layout_weight="1" />
</LinearLayout>

<LinearLayout 
     android:orientation="horizontal"
     android:id="@+id/linearLayout2" android:layout_width="fill_parent"
     android:layout_height="wrap_content" android:paddingTop="15.0dip">

     <Button 
          android:text="Calculate" 
          android:id="@+id/button01"
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content"
          android:layout_weight="1" 
          android:onClick="myClickHandler" />

     <Button 
          android:text="Reset" 
          android:id="@+id/button02"
          android:layout_toRightOf="@+id/button01" 
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" 
          android:layout_weight="1"
          android:onClick="myClickHandler"></Button>
</LinearLayout>

有两种方法可以做到这一点

1) 如果您使用的是线性布局,那么您必须固定左文本视图和左按钮的宽度,然后不能包装内容,只需给他们40度。之后,将右按钮的宽度设置为填充父按钮,或者也为它们设置一个宽度


2) 使用TableLayout并将它们分别放在各自的列和行中,TableLayout会为您处理它。

接下来,我现在要做的是,每个按钮的宽度为0dp,布局权重为1。工作完美,但感谢您的帮助,并为迟交验收感到抱歉。