如何将此布局放入 CardView 中?
How to put this layout in CardView?
所以我有一个布局,我想在 1 个 CardView 中显示前三个 Inputlayouts / EditTexts...下面是我的 XML 和一张图片,它看起来像什么。
希望你能帮帮我。
非常感谢!! :)
这是我的Layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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="match_parent"
android:background="@color/colorBackground">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainActivity">
<LinearLayout
android:id="@+id/information"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:padding="16dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/field_education_year"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Ausbildungsjahr"
android:inputType="number"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false">
<EditText
android:id="@+id/field_week_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:hint="week start"
android:inputType="text|date"
android:onClick="onClick" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false">
<EditText
android:id="@+id/field_week_end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:hint="week end"
android:inputType="text|date"
android:onClick="onClick" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/field_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/field_notice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Notice"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_submit_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="16dp"
android:src="@drawable/ic_publish_new_report" />
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
嗯,首先,我想每个人都会同意几乎所有 RelativeLayout
都没有用。他们实际上什么都不做,相信我。你可以删除它们,它会完全一样。
话虽如此,让我们进入正题。您想要 Cardview
中的那三个 EditText
,但是 CardView
只包含一个子项。您必须将 CardView
和 LinearLayout
或 RelativeLayout
放在里面,并且在该布局中放置其他所有内容。
就像这样:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/information"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:padding="16dp"
tools:context=".activities.MainActivity">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp">
<EditText
android:id="@+id/field_education_year"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Ausbildungsjahr"
android:inputType="number"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:focusableInTouchMode="false">
<EditText
android:id="@+id/field_week_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:hint="week start"
android:inputType="text|date"
android:onClick="onClick" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:focusableInTouchMode="false">
<EditText
android:id="@+id/field_week_end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:hint="week end"
android:inputType="text|date"
android:onClick="onClick" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp">
<EditText
android:id="@+id/field_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp">
<EditText
android:id="@+id/field_notice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Notice"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_submit_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="16dp"
android:src="@drawable/ic_publish_new_report" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
所以我有一个布局,我想在 1 个 CardView 中显示前三个 Inputlayouts / EditTexts...下面是我的 XML 和一张图片,它看起来像什么。
希望你能帮帮我。
非常感谢!! :)
这是我的Layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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="match_parent"
android:background="@color/colorBackground">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainActivity">
<LinearLayout
android:id="@+id/information"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:padding="16dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/field_education_year"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Ausbildungsjahr"
android:inputType="number"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false">
<EditText
android:id="@+id/field_week_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:hint="week start"
android:inputType="text|date"
android:onClick="onClick" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false">
<EditText
android:id="@+id/field_week_end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:hint="week end"
android:inputType="text|date"
android:onClick="onClick" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/field_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:gravity="center">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/field_notice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Notice"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_submit_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="16dp"
android:src="@drawable/ic_publish_new_report" />
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
嗯,首先,我想每个人都会同意几乎所有 RelativeLayout
都没有用。他们实际上什么都不做,相信我。你可以删除它们,它会完全一样。
话虽如此,让我们进入正题。您想要 Cardview
中的那三个 EditText
,但是 CardView
只包含一个子项。您必须将 CardView
和 LinearLayout
或 RelativeLayout
放在里面,并且在该布局中放置其他所有内容。
就像这样:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/information"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:padding="16dp"
tools:context=".activities.MainActivity">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp">
<EditText
android:id="@+id/field_education_year"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Ausbildungsjahr"
android:inputType="number"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:focusableInTouchMode="false">
<EditText
android:id="@+id/field_week_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:hint="week start"
android:inputType="text|date"
android:onClick="onClick" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:focusableInTouchMode="false">
<EditText
android:id="@+id/field_week_end"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:hint="week end"
android:inputType="text|date"
android:onClick="onClick" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp">
<EditText
android:id="@+id/field_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title"
android:maxLines="1" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp">
<EditText
android:id="@+id/field_notice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Notice"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_submit_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="16dp"
android:src="@drawable/ic_publish_new_report" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>