Android 嵌套的CardView注册表。如何动态调整表单大小?
我被要求创建一个在页面底部有一个大正方形按钮的表单 在这一点上,我需要你的帮助,教我一堂关于布局的课,并帮助我使其成为一个动态大小的表单。我希望字段卡和它们的文本能够动态调整大小,并在屏幕底部用蓝色的大条填充。我能在没有定向限定符的情况下完成吗 我试图满足的设计只是根据屏幕大小将邮政编码向下扩展,并在蓝色条处停止。虽然我会满足于锚定按钮并使用邮政编码字段作为动态填充符,但理想情况下我希望有一个完全动态的表单。谢谢你的帮助!p、 目前有一个scrollview,我想以某种方式使用它,这样小屏幕就可以通过字段向下滚动到按钮Android 嵌套的CardView注册表。如何动态调整表单大小?,android,android-layout,Android,Android Layout,我被要求创建一个在页面底部有一个大正方形按钮的表单 在这一点上,我需要你的帮助,教我一堂关于布局的课,并帮助我使其成为一个动态大小的表单。我希望字段卡和它们的文本能够动态调整大小,并在屏幕底部用蓝色的大条填充。我能在没有定向限定符的情况下完成吗 我试图满足的设计只是根据屏幕大小将邮政编码向下扩展,并在蓝色条处停止。虽然我会满足于锚定按钮并使用邮政编码字段作为动态填充符,但理想情况下我希望有一个完全动态的表单。谢谢你的帮助!p、 目前有一个scrollview,我想以某种方式使用它,这样小屏幕就可
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/abc_action_bar_default_height_material"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar30"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/submit_button"
android:orientation="vertical">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_height="50dp"
android:layout_width="match_parent"
card_view:cardElevation="5dp"
card_view:cardBackgroundColor="#888888"
>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
card_view:cardElevation="5dp"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/reg_email_hint"
android:background="@null"
android:layout_margin="20dp"
>
</EditText>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
card_view:cardElevation="5dp"
android:layout_marginTop="1dp"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/reg_firstName_hint"
android:background="@null"
android:layout_margin="20dp">
</EditText>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
card_view:cardElevation="5dp"
android:layout_marginTop="1dp"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/reg_lastName_hint"
android:background="@null"
android:layout_margin="20dp">
</EditText>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
card_view:cardElevation="5dp"
android:layout_marginTop="1dp"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/reg_password_hint"
android:background="@null"
android:layout_margin="20dp">
</EditText>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
card_view:cardElevation="5dp"
android:layout_marginTop="1dp"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/reg_confirmPassword_hint"
android:background="@null"
android:layout_margin="20dp">
</EditText>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
card_view:cardElevation="5dp"
android:layout_marginTop="1dp"
>
<EditText
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:hint="@string/reg_zipCode_hint"
android:background="@null"
android:layout_margin="20dp"
>
</EditText>
</android.support.v7.widget.CardView>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="@+id/submit_button"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom"
android:background="#21C064"
android:textColor="#ffffff"
android:textSize="20sp"
android:text="Save" />
</LinearLayout>
</android.support.design.widget.AppBarLayout>
</ScrollView>
试试这个
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/submit_button"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="8dp"
android:text="Form Field"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="8dp"
android:text="Form Field"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="8dp"
android:text="Form Field"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="8dp"
android:text="Form Field"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="8dp"
android:text="Form Field"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="8dp"
android:text="Form Field"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="8dp"
android:text="Form Field"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="8dp"
android:text="Form Field"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="8dp"
android:text="Form Field"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="8dp"
android:text="Form Field"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="8dp"
android:text="Form Field"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="8dp"
android:text="Form Field"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="8dp"
android:text="Form Field"
android:textSize="20sp" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="@+id/submit_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="@string/hello_world" />
</LinearLayout>
</ScrollView>
这里的诀窍是给出滚动视图
android:fillViewport=“true”
这样,即使内容很小,scrollview子级也可以作为scrollview获得完整高度
在最后一个表单元素和提交按钮之间添加一个空视图,如下所示
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
这样它将填满所有最大可用空间感谢您的帮助Rajesh。现在我对布局有了更多的了解。还有一个问题要问:表单在我的4英寸设备上看起来很完美,但在我的7英寸平板电脑上,你给我的空间填充视图非常大。有没有办法动态调整按钮或文本视图字体的大小,使它们在平板电脑上更大?也许现在是进行方向限定符的时候了?不要在版面中硬编码字体大小和填充,而是将这些值放在dimens.xml中,并在版面中引用。您可以通过这种方式覆盖平板电脑和手机的值。对于10''平板电脑,在values-sw700中创建dimens.xml,并给出更高的值。我也这么认为。对IDE和android软件包的工作原理仍然是陌生的。仅仅是文件夹名称让代码可以选择不同的dimens.xml,还是Java/xml中的一些行?将光标移动到任何大小值,如textSize或padding,然后执行alt+enter,这将建议您提取资源,单击ok android studio将为您执行此操作。让我们参考这个答案。