【问题标题】:How to develop a maximum and minimum heigh in a vertical layout?如何在垂直布局中制定最大和最小高度?
【发布时间】:2018-04-29 14:14:29
【问题描述】:

我想开发这个设计:

上部布局有一个最大高度,如果超过这个高度:就会显示一个滚动条。并且底部布局有一个最小高度,并且与上部布局的底部对齐

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="5"
        android:orientation="vertical">
        <RelativeLayout
            android:layout_weight="2"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <ScrollView
                android:id="@+id/scrollView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fillViewport="true"
                android:scrollbarStyle="insideInset" >
                <TextView android:id="@+id/quest_question_text"
                    android:padding="5sp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/rectangle_quest"
                    style="@style/entry_style"/>
            </ScrollView>
        </RelativeLayout>   

        <RelativeLayout
            android:layout_weight="3"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <ListView 
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/answer_list"/>
        </RelativeLayout>
    </LinearLayout>

感谢您的宝贵时间!

可能有一种方法可以根据上部布局的大小来设置相对布局的权重。

【问题讨论】:

  • 我不确定你想要什么,但如果你需要 50% 是你的最大值,只需使用线性布局并将 weightsum 设置为 2 并使第一个孩子成为具有 0dp 高度和 layoutweight 1 的滚动视图让我知道你是否想要 xml
  • @Xjasz 我想做的就是我画的,代码可能有很多错误
  • 我知道你想要什么我不知道如何使用 layout_weight 在视图上设置最小宽度我会测试一些东西并回复你
  • 我已回滚您的编辑,因为解决方案应该在他们自己的答案中。请找到它in the revision history 并将其作为自己的答案发布。

标签: android xml layout height max


【解决方案1】:

我能想到的最好的方法是使用这个布局。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical" >

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:scrollbarStyle="insideInset" >

    <TextView
        android:id="@+id/quest_question_text"
        style="@style/entry_style"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/rectangle_quest"
        android:padding="5sp" />
</ScrollView>

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

    <ListView
        android:id="@+id/answer_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>

在创建视图时获取设备的高度并设置滚动视图的最小高度。

scrollView.setMinimumHeight(Height / 2);  <--- for 50%

【讨论】:

    猜你喜欢
    • 2014-06-14
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 2018-04-20
    • 2016-02-15
    • 2011-08-06
    • 2019-03-28
    • 1970-01-01
    相关资源
    最近更新 更多