请看下面的代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#373734"
android:orientation="horizontal" >
<ImageView
android:id="@+id/backToLanguageSelectionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp"
android:paddingTop="5dp"
android:src="@drawable/thunderbolt" />
<ImageView
android:id="@+id/internetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:src="@drawable/globe_small_2" />
<Button
android:id="@+id/giveUpButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="350dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="Button" />
</LinearLayout>这是一个通用的布局代码,我正在使用所有的android活动。问题出在按钮上,我想让它移到最右边的角落。边距似乎不能正常工作,因为在不同的设备中,按钮位于不同的位置。
如何才能将其移动到最右侧的角落,在所有设备中显示相同的内容?
发布于 2013-07-19 16:28:43
我相信您可以在第二个ImageView和您的按钮之间添加一个视图,并将其设置为layout_width="0dp",layout_weight="1“。去掉按钮的左边距。
发布于 2013-07-19 16:03:55
而是用户相对布局。并将android:layout_alignParentRight="true“应用于您的按钮。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#373734"
android:orientation="horizontal" >
<ImageView
android:id="@+id/backToLanguageSelectionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp"
android:paddingTop="5dp"
android:src="@drawable/social_share" />
<ImageView
android:id="@+id/internetButton"
android:layout_toRightOf="@+id/backToLanguageSelectionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:src="@drawable/social_share" />
<Button
android:id="@+id/giveUpButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="Button" />
发布于 2013-07-19 16:01:28
你试过android:layout_gravity="right"吗?
https://stackoverflow.com/questions/17740970
复制相似问题