5

次のコードをご覧ください

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DisplayResult" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >

        <ImageView
            android:id="@+id/zodiac1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/aries"
            />

        <TextView
            android:id="@+id/orTxt"
            android:text="Or"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            />

        <ImageView 
            android:id="@+id/zodiac2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/gemini"
            />

    </LinearLayout>




    </ScrollView>

すべてをLinearLayout内の中央に配置する必要があります。アプリが100%完成すると、スクロールしないと一目で見ることができない情報がたくさんあるので、scrollviewを使用する必要があります。どうすればこれらのセンターを作ることができますか?助けてください!

アップデート

スクロール内の任意のレイアウトを使用します。問題はありません。しかし、私はそれらの要素が同じ順序(次々に)で中央に配置されている必要があります。

4

4 に答える 4

16

線形レイアウトでは、重力を中心に設定する必要があります

< LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:orientation="horizontal" >
于 2012-12-27T19:47:18.130 に答える
3

これは私のために働いた:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<ScrollView 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
>



 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center"
于 2013-08-06T09:54:37.467 に答える
0

にlayout_gravityを使用してみてLinearLayoutくださいcenter_horizontal

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_height="wrap_content"
    android:orientation="horizontal"/>
于 2012-12-27T19:45:39.357 に答える
0
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DisplayResult"
    scrollbars="horizontal">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center_horizontal">

        <ImageView
            android:id="@+id/zodiac1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/aries"
            />

        <TextView
            android:id="@+id/orTxt"
            android:text="Or"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            />

        <ImageView 
            android:id="@+id/zodiac2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/gemini"
            />

    </LinearLayout>




    </ScrollView>

#中央に線形レイアウトを作成する場合は、線形レイアウトにandroid:gravity="center_horizo​​ntal"と記述する必要があります。

于 2020-06-17T18:08:44.653 に答える