gpt4 book ai didi

android - 如何在android中的DataBinding中使用内部布局

转载 作者:行者123 更新时间:2023-11-30 00:35:38 25 4
gpt4 key购买 nike

我在我的应用程序中使用数据绑定(bind)。我创建了一个布局,并且还包含了一个布局,但是当我想使用包含的布局变量时,我找不到他。

这是我的 Java 类:-

    public class CancelCase extends AppCompatActivity {

private CancelCaseBinding mBinding;

private static final String TAG = CancelCase.class.getSimpleName();
private Context context = null;


private AppCompatImageView imgViewBack;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// initialization context
context = this;

// Inflate the layout for this activty
mBinding = DataBindingUtil.setContentView(this, R.layout.cancel_case);

mBinding.world1.



// MainBinding binding = MainBinding.inflate(getLayoutInflater());


// setTypeface();

}
private void setTypeface(){

}
}

这里是我的主要布局。

    <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="auth"
type="com.octalsoftaware.archi.viewmodals.AuthViewModel" />
</data>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/whitecolor"
android:orientation="vertical">

<include
android:id="@+id/world1"
layout="@layout/customtoolbar"/>


<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/txt_submit"
android:layout_below="@+id/world1">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">


<TextView
android:id="@+id/txt_patientname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar"
android:padding="@dimen/_10sdp"
android:text="Linder William"
android:textColor="@color/blackcolor"
android:textSize="@dimen/_15sdp"
android:textStyle="bold" />

<LinearLayout
android:id="@+id/ll_cancelcase"
android:layout_width="match_parent"
android:layout_height="@dimen/_50sdp"
android:background="@drawable/blue_bg"
android:orientation="horizontal"
android:padding="@dimen/_15sdp">

<TextView
android:id="@+id/txt_cancelcases"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel_case"
android:textColor="@color/whitecolor"
android:textSize="@dimen/_15sdp"
android:textStyle="bold" />

<TextView
android:id="@+id/txt_selectonly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_5sdp"
android:text="@string/select_only_one"
android:textColor="@color/whitecolor"
android:textSize="@dimen/_13sdp" />

</LinearLayout>


<LinearLayout
android:id="@+id/ll_beforeinducation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/checkboxbackgroundcolor"
android:orientation="vertical">


<CheckBox
android:id="@+id/checkbox_before"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_10sdp"
android:button="@drawable/checkbox_select"
android:checked="true"
android:padding="@dimen/_15sdp"
android:text="@string/before_induction"
android:textColor="@color/checkboxtextcolor"
android:textSize="@dimen/_15sdp" />

</LinearLayout>

<LinearLayout
android:id="@+id/ll_afterinducation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/whitecolor"
android:orientation="vertical">


<CheckBox
android:id="@+id/checkbox_after"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_10sdp"
android:background="@color/whitecolor"
android:button="@drawable/checkbox_select"
android:checked="true"
android:padding="@dimen/_15sdp"
android:text="@string/after_induction"
android:textColor="@color/checkboxtextcolor"
android:textSize="@dimen/_15sdp" />


</LinearLayout>

<LinearLayout
android:id="@+id/ll_reason"
android:layout_width="match_parent"
android:layout_height="@dimen/_50sdp"
android:background="@drawable/blue_bg"
android:orientation="horizontal"
android:padding="@dimen/_15sdp">

<TextView
android:id="@+id/txt_reason"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reason"
android:textColor="@color/whitecolor"
android:textSize="@dimen/_15sdp" />

<TextView
android:id="@+id/txt_selectallapply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_5sdp"
android:text="@string/reason_select_all_that_apply"
android:textColor="@color/whitecolor"
android:textSize="@dimen/_13sdp" />

</LinearLayout>

<LinearLayout
android:id="@+id/ll_system"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/checkboxbackgroundcolor"
android:orientation="vertical">


<CheckBox
android:id="@+id/checkbox_system"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_10sdp"
android:button="@drawable/checkbox_select"
android:checked="true"
android:padding="@dimen/_15sdp"
android:text="@string/system"
android:textColor="@color/checkboxtextcolor"
android:textSize="@dimen/_15sdp" />

</LinearLayout>

<LinearLayout
android:id="@+id/ll_medical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/whitecolor"
android:orientation="vertical">


<CheckBox
android:id="@+id/checkbox_medical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_10sdp"
android:background="@color/whitecolor"
android:button="@drawable/checkbox_select"
android:checked="true"
android:padding="@dimen/_15sdp"
android:text="@string/medical"
android:textColor="@color/checkboxtextcolor"
android:textSize="@dimen/_15sdp" />


</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/_10sdp"
android:background="@color/checkboxbackgroundcolor"
android:orientation="vertical">


<CheckBox
android:id="@+id/checkbox_patient"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_10sdp"
android:button="@drawable/checkbox_select"
android:checked="true"
android:padding="@dimen/_15sdp"
android:text="@string/patient"
android:textColor="@color/checkboxtextcolor"
android:textSize="@dimen/_15sdp" />

</LinearLayout>

</LinearLayout>
</ScrollView>


<TextView
android:id="@+id/txt_submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:background="@drawable/blue_bg"
android:gravity="center"
android:paddingBottom="@dimen/_12sdp"
android:paddingTop="@dimen/_12sdp"
android:text="@string/submit"
android:textColor="@color/whitecolor"
android:textSize="@dimen/_15sdp"
android:textStyle="bold" />


</RelativeLayout>

</layout>

这里是我的 include 布局:-

    <?xml version="1.0" encoding="utf-8"?>


<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="@color/whitecolor">

<android.support.v7.widget.AppCompatImageView
android:id="@+id/toggle_icon"
android:layout_width="wrap_content"
android:layout_height="?actionBarSize"
android:layout_marginLeft="@dimen/_20sdp"
app:srcCompat="@drawable/ic_arrow_back_black_24dp" />

<TextView
android:id="@+id/toolbarheading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="20dp"
android:textColor="@color/blackcolor"
android:textSize="@dimen/_15sdp" />


<ImageView
android:layout_width="wrap_content"
android:layout_height="?actionBarSize"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/_20sdp"
android:src="@android:drawable/ic_menu_edit" />
</RelativeLayout>

<View
android:layout_width="match_parent"
android:layout_height="@dimen/_1sdp" />

</android.support.v7.widget.CardView>

我看到很多答案,但找不到正确的解决方案。

最佳答案

customtoolbar.xml 文件中使用 layout 标签

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">

</android.support.v7.widget.CardView>
</layout>

关于android - 如何在android中的DataBinding中使用内部布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43463609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com