android - 3 种布局 - 中间是灵活的

标签 android android-layout

我需要以下东西:

3 种布局:

  1. 标题
  2. 内容
  3. 页脚

页眉必须在顶部,页脚必须贴在底部 (android:layout_alignParentBottom="true")。

但是如何让中间占据整个其他屏幕?谢谢。

最佳答案

这是我的解决方案(使用 android:layout_weight 和 ScrollView):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="#DDDDDD"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Header"
        tools:ignore="HardcodedText" />
</LinearLayout>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="3" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Content"
        tools:ignore="HardcodedText" />

</ScrollView>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="#DDDDDD"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Footer"
        tools:ignore="HardcodedText" />

</LinearLayout></LinearLayout>

结果图片:

enter image description here

关于android - 3 种布局 - 中间是灵活的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16627039/

相关文章:

Android - 在 Lollipop 之前的设备上为 ProgressBar 着色

android - 同时使用 setOnItemClickListener 和 setOnItemLongClickListener 两个监听器同时触发或同时工作。为什么

java - 如何将对象序列化为JSON?

android - 服务是否有 onBackPressed() 替代方案?

android - 从后台线程添加 View

android - 在另一个 fragment 之上显示 fragment

android - TextView 不显示任何文本

java - 获取选中的单选按钮值

android - 创建新的 Android 项目时出现 java.lang.NoClassDefFoundError

Android - 多次使用图像资源但仅在 1 个实例上更改 alpha