Android 简单布局问题-将菜单按钮对准最右侧,居中

Android 简单布局问题-将菜单按钮对准最右侧,居中,android,android-layout,Android,Android Layout,让一个图标缩成我想要的位置有很多困难。我看了3个不同的堆栈溢出问题,并尝试将图像放置在相对的Layout、LinearLayout和TableRow中。所有这些都具有各种XML选项。从未设法使图标向右移动,并在分配空间的顶部和底部之间居中。在下面的图片中,红色是现在的位置,蓝色是我想要的位置。这是一张图片(它现在看起来如何,这是不正确的)和代码(imageView1是我想要对齐的): 以及守则: <?xml version="1.0" encoding="utf-8"?> <

让一个图标缩成我想要的位置有很多困难。我看了3个不同的堆栈溢出问题,并尝试将图像放置在相对的Layout、LinearLayout和TableRow中。所有这些都具有各种XML选项。从未设法使图标向右移动,并在分配空间的顶部和底部之间居中。在下面的图片中,红色是现在的位置,蓝色是我想要的位置。这是一张图片(它现在看起来如何,这是不正确的)和代码(imageView1是我想要对齐的):

以及守则:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:id="@+id/loginScrollView">
    <TableLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:orientation="vertical"
        android:padding="5dp">

        <ImageView android:id="@+id/logoImageView"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:src="@drawable/logo" android:contentDescription="@string/app_name" />

        <TextView android:id="@+id/demoTextView"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:text="@string/logDetails" android:gravity="center_horizontal|center" />

        <EditText android:id="@+id/emailEditText"
            android:layout_width="match_parent" android:layout_height="wrap_content"
            android:hint="@string/loginHint" android:imeOptions="actionNext"
            android:inputType="textEmailAddress" android:padding="20dp" />

        <EditText android:id="@+id/passEditText"
            android:layout_width="match_parent" android:layout_height="wrap_content"
            android:hint="@string/password" android:imeOptions="actionDone"
            android:inputType="textPassword" android:padding="20dp" />

        <TableRow android:id="@+id/rememberTableRow"
            android:layout_width="wrap_content" android:layout_height="wrap_content">
            <TextView android:id="@+id/rememberTextView"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:text="@string/rememberDetails" android:layout_gravity="center" />

            <CheckBox android:id="@+id/rememberCheckBox"
                android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:padding="20dp" />

            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="showPopup"
                android:src="@drawable/abs__ic_menu_moreoverflow_holo_dark" android:layout_weight="1" android:layout_gravity="center|right"/>

        </TableRow>

        <TableRow android:id="@+id/buttonTableRow"
            android:layout_width="match_parent" android:layout_height="wrap_content">

            <Button android:id="@+id/registerButton" android:layout_width="0dip"
                android:layout_height="wrap_content" android:layout_gravity="bottom"
                android:layout_weight="1" android:text="@string/register" />

            <Button android:id="@+id/loginButton" android:layout_width="0dip"
                android:layout_height="wrap_content" android:layout_gravity="bottom"
                android:layout_weight="1" android:text="@string/login" />
        </TableRow>

    </TableLayout>
</ScrollView>

以下是我已经研究并尝试用作解决方案的SO问题:
据我所知,有多种选择。我给你两个:

第一个选项是在包含溢出图标的ImageView上设置scaletype。您可以让它占用所有剩余的可用空间,并将scaletype设置为
fitEnd
。这将使图标一直位于右侧

<ImageView android:id="@+id/imageView1"
    android:layout_width="0dp" android:layout_height="wrap_content"
    android:layout_gravity="center_vertical" android:scaleType="fitEnd"
    android:layout_weight="1" android:onClick="showPopup"
    android:src="@drawable/abs__ic_menu_moreoverflow_normal_holo_dark" />

需要帮助的imageview在哪里?它在图片中吗?是的,它是复选框右侧的一个:它看起来像一个标准菜单图标(3个垂直框)。啊,我刚到家,有人回答了它。哈,不管怎样,我给了你一个有用的评论!谢谢你的夸奖!android:scaleTyle=“fitEnd”工作得非常好。实际上,我删除了我试图用来放置菜单图像的TableRow。我以前没见过scaleType,所以非常感谢!
<TableRow android:id="@+id/rememberTableRow"
    android:layout_width="wrap_content" android:layout_height="wrap_content">

    <TextView android:id="@+id/rememberTextView"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_gravity="center" android:text="@string/rememberDetails" />

    <CheckBox android:id="@+id/rememberCheckBox"
        android:layout_width="0dp" android:layout_height="wrap_content"
        android:layout_weight="1" android:padding="20dp" />

    <ImageView android:id="@+id/imageView1"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_gravity="center_vertical" android:onClick="showPopup"
        android:src="@drawable/abs__ic_menu_moreoverflow_normal_holo_dark" />

</TableRow>