ScrollView中的最小高度fill_parent和高度wrap_content?(或只是电子邮件应用程序撰写布局代码)

Bry*_*eld 25 android android-layout

问题如果我有以下内容:

<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout android:layout_width="fill_parent" android:layout_height="?" android:orientation="vertical">
        <EditText android:layout_width="fill_parent" android:layout_height="?" android:hint="Subject" android:id="@+id/subject" />
        <EditText android:layout_width="fill_parent" android:layout_height="?" android:id="@+id/body" />
    </LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

如何让身体(第二个EditText)填充屏幕的其余部分,但是当身体内容太长时仍然会有滚动视图?喜欢height="wrap_content"minHeight="fill_parent"

layout_height="fill_parent" 如果你把它们放在一个scrollview中似乎没有做任何事情

我想要的一个工作示例是电子邮件应用程序撰写窗口

我试过这个,EditText元素就像是wrap_content一样,没有填充.如果输入足够的话,只需滚动即可

<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
        <EditText android:layout_width="fill_parent" android:layout_height="fill_parent" layout_weight="1" android:hint="Subject" android:id="@+id/subject" />
        <EditText android:layout_width="fill_parent" android:layout_height="fill_parent" layout_weight="1" android:id="@+id/body" />
    </LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

Bry*_*eld 74

在另一个问题上遇到我接受的答案中邮件应用程序源代码的链接.答案很简单!添加到视图并添加到视图中以占用所有可用空间.在这个博客中解释android:fillViewport="true"<ScrollView...>android:layout_weight="1.0"

  • 对于那些遇到这种情况的人,不要忘记你需要像我上面那样指定重量. (6认同)

dea*_*nik 5

如上所述,正确的方法是使用android:fillViewport ="true"属性.

有一个例子,其中图像定位为和scrollview:

  <ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">
    <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:fillViewport="true"
      android:orientation="vertical">

      <LinearLayout
        android:layout_height="fill_parent"
        android:layout_width="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1">
        <TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="test"/>
      </LinearLayout>


      <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="@color/red">
        <ImageView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:adjustViewBounds="true"
          android:src="@drawable/about_us_image_1_land"
          style="@style/layout_marginTop20"/>
      </LinearLayout>
    </LinearLayout>
   </ScrollView>
Run Code Online (Sandbox Code Playgroud)