特定の方法で位置合わせする必要のある複数の画像があります。2番目の画像imageview
は最初の画像の中央に位置合わせする必要がありimageview
ます。どうすればそれを達成できますか?
参考のために画像を添付しましたが、
今のところ、私がやっていることは、中央に隠されたビューを維持し、obj1
その上部をその上に揃えるobj2
ことですが、うまくいかないようです。
特定の方法で位置合わせする必要のある複数の画像があります。2番目の画像imageview
は最初の画像の中央に位置合わせする必要がありimageview
ます。どうすればそれを達成できますか?
参考のために画像を添付しましたが、
今のところ、私がやっていることは、中央に隠されたビューを維持し、obj1
その上部をその上に揃えるobj2
ことですが、うまくいかないようです。
paddingTop
obj3の を取得しないと、その半分は obj1 のpaddingTop
ormarginTop
になります。
:の配置を使用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>
これを自分で試すことができます。これが、要件に応じてビューを取得するのに役立つことを願っています-
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);
}
}
これは正確な答えではありません。しかし、これは目的の出力を得るのに役立つはずです。