0

私の問題は、他の人にとっては些細なことかもしれませんが、私にとってはそれを機能させることができません。次のようなレイアウトxmlがあります。

<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"
    >

    <LinearLayout android:id="@+id/tracker_container"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:orientation="vertical"
        />

    <ImageView
        android:id="@+id/mainImageView"
        android:contentDescription="@string/display"        
        android:layout_gravity="center"
        android:layout_width="400dp"
        android:layout_height="300dp"
        android:opacity="translucent" 

        />

</LinearLayout>

ImageView画面全体の中央にあるようにするにはどうすればよいですか? ありがとう

4

2 に答える 2

0

RelativeLayoutを親として使用し、次を使用できlayout_centerInParentます。

<RelativeLayout 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">

    <LinearLayout android:id="@+id/tracker_container"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:orientation="vertical" />

    <ImageView
        android:id="@+id/mainImageView"
        android:contentDescription="@string/display"        
        android:layout_centerInParent="true"
        android:layout_width="400dp"
        android:layout_height="300dp"
        android:opacity="translucent" />

</RelativeLayout>

何の為か分かりませんLinearLayoutが保管しておりました。おそらく、あなたはプログラムでそれを設定していて、それがあなたを押し下げていますImageViewRelativeLayout他のビュー要素に関係なく、常に親の中心になります。

于 2013-06-30T08:36:21.633 に答える