android - 在同一水平线上点亮两个按钮

标签 android android-layout android-button

我试图让“保存”和“附加图片”按钮在我的 xml 页面的顶部对齐,但我无法让它正常工作。我得到了按钮将不在同一水平线上对齐的地步。哦,有什么方法可以让两个按钮在左上角和右上角对齐? 这是 xml 页面:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">

<RelativeLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:background="#ffffff" >

  <!-- Footer Start -->

  <LinearLayout
      android:id="@+id/footer"
      android:layout_width="fill_parent"
      android:layout_height="90dip"
      android:layout_alignParentBottom="true"
      android:background="@layout/footer_repeat"
      android:orientation="horizontal" >
  </LinearLayout>
  <!-- Footer Ends -->


  <LinearLayout
      android:id="@+id/linearLayout1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:padding="10dip" >

      <!-- Save button -->

      <Button
          android:id="@+id/btnSavePic"
          style="?android:attr/buttonStyleSmall"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_marginTop="10dip"
          android:text="@string/savePic"
          android:layout_gravity="top|left"/>

       <Button
          android:id="@+id/btnAttachPic"
          style="?android:attr/buttonStyleSmall"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_marginTop="10dip"
          android:text="@string/attachPic"
          android:layout_gravity="top|right"/>
  </LinearLayout>



</RelativeLayout>

</ScrollView>

添加图片: http://tinypic.com/view.php?pic=4ihut4&s=5#.Uj9eHBbnZAh

最佳答案

我建议使用封闭的 LinearLayout:

<LinearLayout
  android:id="@+id/linear_layout"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
  >


  <Button
      android:id="@+id/btnSavePic"      
      android:layout_width="0dip"
      android:layout_weight="1"
      android:layout_height="wrap_content"      
      android:text="@string/savePic"
      />

   <Button
      android:id="@+id/btnAttachPic"
      android:layout_width="0dip"
      android:layout_weight="1"
      android:layout_height="wrap_content"      
      android:text="@string/attachPic"
      />
</LinearLayout>

关于android - 在同一水平线上点亮两个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18948765/

相关文章:

android - Material 按钮的禁用颜色状态

android - 一个扩展 Activity 和 BroadcastReceiver 的类

android - 在 Android 中,我如何找出在运行时处理 Intent 的类(logcat 很好)

Android map 加载错误

android - 使用相同的 Activity 在 Android 中查看翻转

java - ListView 未对齐

android - 带阴影的圆形按钮 5.0 FAB

android - 我如何在 android 中实用地添加和删除布局?

java - 找不到以下类: - ImageButton (Change to android. widget.ImageButton,修复构建路径,编辑XML)

Android 是否可以从服务中获取 Activity 偏好值?