0

アイコンを希望の位置に配置するのに苦労しました.3つの異なるスタックオーバーフローの質問を見て、画像をRelativeLayout、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 の質問は次の とおりです

4

1 に答える 1

1

私が知る限り、複数のオプションがあります。私はあなたに2つあげます:

最初のオプションは、オーバーフロー アイコンを含む 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" />

CheckBox に重みを設定することで同じ効果を得ることができ1ます。これにより、オーバーフロー アイコンを含む ImageView が右端まで「プッシュ」されます (LinearLayout と同様に動作する TableRow のおかげです)。次に、ImageView にそのコンテンツをラップさせるだけです。ただし、この場合、クリック可能な領域に奇妙な副作用がないかどうかを再確認することをお勧めします。

<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>
于 2012-04-05T21:49:54.177 に答える