【问题标题】:How to set layout height to one screen height except actionbar and status bar, in scrollview如何在滚动视图中将布局高度设置为除操作栏和状态栏外的一个屏幕高度
【发布时间】:2016-06-26 16:23:09
【问题描述】:

我在滚动视图中有一个布局,我在第一个布局的末尾添加了另一个布局。实际上,我正在尝试进行单页设计,其余的其他视图将在滚动后出现。我试图将 linearlayout1 和 linearlayout2 放到另一个视图中,但是没有用。我还设置了滚动视图 android:fillViewport="true" 但它使滚动视图变成了屏幕大小。

我已经添加了我想要的图像,但它也可以是一个视图,我的意思是 lin1 和 lin2 在一起。

我可以为一部手机设置宽度和高度,但我想为每个屏幕都这样做。例如像雅虎天气应用程序。他们为第一个视图做了一个布局,并从屏幕末尾开始另一个视图。我尝试了很多东西,但我无法想象如何放置布局。你能帮帮我吗?

感谢您的帮助

这就是我想要的

我试过了:

<?xml version="1.0" encoding="utf-8"?>

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scroller"
        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:orientation="vertical">

            <LinearLayout
                android:id="@+id/linearlayout1"
                android:background="@android:color/holo_purple"
                android:layout_width="match_parent"
                android:layout_height="350dp" >

                <TextView
                    android:text="LinearLayout1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearlayout2"
                android:background="@android:color/holo_blue_bright"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:orientation="vertical">

                <TextView
                    android:text="LinearLayout2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:background="@android:color/holo_green_light"
                android:layout_width="match_parent"
                android:layout_height="350dp">

                <TextView
                    android:text="LnearLayout3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

            </LinearLayout>



        </LinearLayout>
    </ScrollView>

但不幸的是,我无法为每个屏幕尺寸进行配置。

enter image description here

【问题讨论】:

  • 请提供您的 xml。我猜你需要为你的滚动视图添加 match_parent 高度,但我不能确定没有 xml
  • 我用 xml 编辑并添加了一张我无法想象的图像

标签: android layout alignment scrollview


【解决方案1】:

试试这个。

        android:layout_width="fill_parent"
        android:layout_height="fill_parent"        
        android:layout_below="@+id/action_bar"

【讨论】:

    【解决方案2】:

    而不是像这样硬编码高度:

    android:layout_height="250dp"
    

    设置android:layout_height="0dp"并使用

    android:layout_weight="25"
    

    并且还在其他布局中使用权重。重量是这样工作的,如果您的容器中有 3 个组件,请将权重设置为 1、2 和 3 => 它们将按容器的 1/6、2/6 和 3/6 的顺序排列。 6 是 1,2,3 的总和。因此,在这里,您可以将高度设置为 0 并使用 2.5 和 3.5 或 25 和 35,而不是使用高度 350 和 250。

    【讨论】:

    • 我按重量比例,没关系,但我想将第一个线性布局高度设置为一个屏幕大小,滚动后会出现其余视图?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多