3
ConstraintLayoutを別のConstraintLayoutにプログラム的に配置したいとします。しかし、私がRelativeLayoutを使って前にしたようにそれを膨らませると、それは現れません。他のConstraintLayoutでConstlLayoutを膨張させる
ここでは、コード内部のファイルinner_area.xmlです:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/innerArea"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/grade_one"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:background="@drawable/onegreen"
app:layout_constraintBottom_toTopOf="@+id/h1"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/v1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:layout_conversion_absoluteHeight="20dp"
tools:layout_conversion_absoluteWidth="30dp"
tools:layout_conversion_absoluteX="0dp"
tools:layout_conversion_absoluteY="0dp" />
<ImageView
android:id="@+id/grade_three"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:background="@drawable/threelila"
app:layout_constraintBottom_toTopOf="@+id/h2"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/v1"
app:layout_constraintTop_toTopOf="@+id/h1"
app:layout_constraintVertical_bias="0.0"
tools:layout_conversion_absoluteHeight="20dp"
tools:layout_conversion_absoluteWidth="30dp"
tools:layout_conversion_absoluteX="0dp"
tools:layout_conversion_absoluteY="20dp" />
.....
</android.support.constraint.ConstraintLayout>
外LayoutFileのparent.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/parentView"
android:background="@color/primary">
</android.support.constraint.ConstraintLayout>
Javacode:
ViewGroup parentView = rootView.findViewById(R.id.parentView);
final ConstraintLayout innerArea = (ConstraintLayout) inflater.inflate(R.layout.inner_area, container, false);
parentView.addView(innerArea);
しかし、私は内部で変化します。 xml layout_widthまたはlayout_heightのinnerAreaをwrap_contentまたはmatch_parentに設定すると、何も起こりません。しかし、2000dpに変更すると、内部レイアウトが表示されます。
私は間違っているか紛失していますか?
あなたは ')(膨らま'で親としてcontainer' 'で膨らまされています。私は正しいJavacodeがあるので、であることを想定している制約レイアウトでルートレイアウトでConstraintLayoutを膨張させるとされていません膨張されたレイアウトを 'parentView'に追加しています。これは正しいとは思わない。 'rootView'と' container'が何であるか知ることは役に立ちます。これはフラグメントの 'onCreateView()'の一部のように見えるので、フラグメントトランザクションを見ることも役に立つかもしれません。 – Cheticamp