2017-10-08 2 views
3

ConstraintLayout을 다른 ConstraintLayout에 프로그래밍 방식으로 배치하려고합니다. 그러나 RelativeLayout을 사용하여 이전에했던 것처럼 부풀려지면 표시되지 않습니다. 내가 내부에서 변경할 때ConstraintLayout을 다른 ConstraintLayout으로 팽창시키기

ViewGroup parentView = rootView.findViewById(R.id.parentView); 
    final ConstraintLayout innerArea = (ConstraintLayout) inflater.inflate(R.layout.inner_area, container, false); 
    parentView.addView(innerArea); 

그러나 :

<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

다음은 코드 내부 파일 inner_area.xml입니다. xml layout_width 또는 layout_height innerArea wrap_content 또는 match_parent, 아무 일도 발생하지 않습니다. 하지만 2000dp로 변경하면 내부 레이아웃이 표시됩니다.

내가 잘못했거나 누락 되었습니까?

+0

:. 나는 올바른 Javacode는 그래서에 있어야하는데 제약 레이아웃과 루트 레이아웃으로 ConstraintLayout을 팽창 및되지 않았습니다 그러나 당신은 팽창 된 레이아웃을'parentView'에 추가하고 있습니다. 이것은 옳지 않은 것처럼 보입니다. 'rootView'와'container'가 무엇인지 아는 것이 도움이 될 것입니다. 이것은 프래그먼트의 onCreateView()의 일부처럼 보이므로 프래그먼트 트랜잭션을 살펴 보는 것도 도움이 될 수 있습니다. – Cheticamp

답변

1

Cheticamp 덕분에 올바른 방향으로 나를 가리켜주었습니다. `) (당신은 팽창 '에서 부모로 container``로 팽창되어

parentView = rootView.findViewById(R.id.parentView); 
    ViewGroup parentView = rootView.findViewById(R.id.parentView); 
    final ConstraintLayout innerArea = (ConstraintLayout) 
    inflater.inflate(R.layout.inner_area, parentView, false); 
    parentView.addView(innerArea); 
관련 문제