我试图让“保存”和“附加图片”按钮在我的 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/