2 回答
TA贡献1856条经验 获得超11个赞
没有父级的膨胀方法将丢失布局参数(高度,宽度)
private void initView() {
inflate(getContext(), R.layout.accordion_item, this);
// or
// View view = LayoutInflater.from(getContext()).inflate(R.layout.accordion_item, this, false);
// addView(view);
}
TA贡献1846条经验 获得超7个赞
你真的不需要这个简单布局的库,看看这个例子:
<androidx.constraintlayout.widget.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"
tools:context=".Fragments.CheckoutScreen">
<!-- This is an example of how my view should look like -->
<CheckBox
android:id="@+id/favourite_checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="@+id/textView4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/textView4" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="T"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="@+id/textView4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/textView4" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Title"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView5"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.383" />
添加回答
举报