あなたがViewAに、または上ViewBを追加する場合のようにあなたは、このマージン、パディング、高さを再生するためのViewGroupのあらゆる種類の幅を持つことになりますが、このような何かを、あなたはRelativeLayoutのようなViewGroupsの種類を勉強しなければならないだろう、 LinearLayout、ConstraintLayoutなど
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="250dp"
android:background="#000"
android:layout_centerInParent="true"
android:layout_height="250dp"></LinearLayout>
</RelativeLayout>
ありません、.xmlファイルで常にあなたのビューを作成する必要は全くありません。 2番目の部分については、5つのボタンを1つのビューに配置し、プログラムによって、下のコードで前後に移動できます。
public void moveForward() {
int childCount = mParentLayoutOfTheView.getChildCount();
if (childCount > 1) {
int index = mParentLayoutOfTheView.indexOfChild(mChildLayout);
if (index < childCount - 1) {
mParentLayoutOfTheView.removeView(mChildLayout);
mParentLayoutOfTheView.addView(mChildLayout, index + 1);
}
}
}
後方移動
public void moveBackward() {
int childCount = mParentLayoutOfTheView.getChildCount();
if (childCount > 1) {
int index = mParentLayoutOfTheView.indexOfChild(mChildLayout);
if (index > 0) {
mParentLayoutOfTheView.removeView(mChildLayout);
mParentLayoutOfTheView.addView(mChildLayout, index - 1);
}
}
}
それがお役に立てば幸いです。
'ViewGroup'sで遊んでみませんか? – Sweeper