android使 View 包装内容但不大于特定大小

标签 android layout android-relativelayout

我有一个相对 View ,它有两个 subview ,一个 ScrollView 和一个按钮,现在我想这样做:我希望这个 View 包装它的内容,不留出空白空间,也不超过屏幕尺寸。 我怎样才能做到这一点?谁能帮忙?

这是我当前无法使用的布局文件。

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ScrollView
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
              ....
     </ScrollView>
     <Button
        android:id="@+id/action"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/content" 
        ... />
</RelativeLayout>

最佳答案

RelativeLayout 没有这种可能性。但是 LinearLayout 可以。只需将LinearLayoutandroid:orientation设置为vertical,设置ScrollViewandroid:layout_weight1,它应该可以工作了:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    </ScrollView>

    <Button
        android:id="@+id/action"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

关于android使 View 包装内容但不大于特定大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40842448/

相关文章:

Android GridView 垂直加载项目

java - 在 Java 中将 JLabel 放在 JLabel 之上

html - 创建如下布局的最佳方法?

android - ExpandableListView的ScrollView和RelativeLayout滚动问题

android - 包装内容不起作用并且滚动停止工作

android - 将 FrameLayout 分配为父 RelativeLayout 的一半

android - 现在必须显式声明 Kapt 注释处理器

android - 如果 gradle-android-test-plugin 测试失败,不要让 gradle 构建失败

安卓ADT : Moving views mixes up IDs (bug?)

android - 不同屏幕显示不一样的界面