2

特定の方法で位置合わせする必要のある複数の画像があります。2番目の画像imageviewは最初の画像の中央に位置合わせする必要がありimageviewます。どうすればそれを達成できますか?ここに画像の説明を入力してください

参考のために画像を添付しましたが、

今のところ、私がやっていることは、中央に隠されたビューを維持し、obj1その上部をその上に揃えるobj2ことですが、うまくいかないようです。

4

3 に答える 3

1

paddingTop obj3の を取得しないと、その半分は obj1 のpaddingTopormarginTopになります。

于 2013-02-01T09:00:56.557 に答える
0

:の配置を使用RelativeLayoutおよび設定します。ImageViews

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageViewLeft"
            android:layout_alignParentLeft="true"/>

    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageViewRight"
            android:layout_alignParentRight="true"/>
</RelativeLayout>
于 2013-02-01T08:31:20.673 に答える
0

これを自分で試すことができます。これが、要件に応じてビューを取得するのに役立つことを願っています-

activity_main.xml を作成する

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlBase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFF000" >

<ImageView
    android:id="@+id/imageViewRight"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageViewLeft"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:src="@drawable/ic_launcher" />

</RelativeLayout> 

imagemiddle.xml を作成する

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageViewMiddle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />

主な活動では -

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}

と -

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    // TODO Auto-generated method stub
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        RelativeLayout rlParent = (RelativeLayout) findViewById(R.id.rlBase);
        int height = rlParent.getMeasuredHeight() / 2;
        Log.d("Height:", height + "");
        rlParent.getLayoutParams().height = height
                + rlParent.getMeasuredHeight();
        rlParent.invalidate();// Change the height of the Relative layout programatically

        // Layout params for the middle image--
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.CENTER_HORIZONTAL,
                RelativeLayout.TRUE);
        LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        ImageView ivMiddle = (ImageView) inflater.inflate(
                R.layout.imagemiddle, null);
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,
                RelativeLayout.TRUE);
        ivMiddle.setLayoutParams(params);
        rlParent.addView(ivMiddle, params);

    }
}

これは正確な答えではありません。しかし、これは目的の出力を得るのに役立つはずです。

于 2013-02-01T09:40:49.163 に答える