1

请看下面的代码

<?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 活动的通用布局代码。问题是按钮,我希望它移动到最右上角。保证金的东西似乎无法正常工作,因为在不同的设备中,按钮位于不同的位置。

我怎样才能将它移动到最右边的角落,这将在所有设备中显示相同?

4

5 回答 5

4

我相信您可以在第二个 ImageView 和按钮之间添加一个视图,并将其设置为 layout_width="0dp"、layout_weight="1"。并删除按钮的左边距。

于 2013-07-19T08:28:43.367 回答
2

而是用户相对布局。并将 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-19T08:03:54.850 回答
0

你试过android:layout_gravity="right"吗?

于 2013-07-19T08:01:27.667 回答
0

它可以用RelativeLayout

<Button
    android:id="@+id/giveUpButton"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginLeft="350dp"
    android:paddingBottom="5dp"
    android:paddingTop="5dp"
    android:text="Button"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true" />
于 2013-07-19T08:12:38.253 回答
0

使用 RelativeLayout 并将其高度设置为尽可能小。这样,屏幕的一小部分将被填满。当您使用RelativeLayout 时,您可以使用android:layout_alignParentRight="true"将任何项目放在右边。android:scaleType="centerInside"现在,如果按钮缩放有问题,您可以使用图像并设置它,而不是按钮。我和你有同样的问题,我用RelativeLayout解决了它。

于 2013-07-19T08:41:53.227 回答