【发布时间】:2015-03-08 08:43:26
【问题描述】:
我正在开发一个需要具有静态尺寸的线性布局的 android 项目。但是我的线性布局的高度超过了屏幕尺寸(2000dp),所以我把它放在了一个 ScrollView 中。
问题在于它的高度不是静态的,而是等于屏幕高度。
如何解决这个问题?
<RelativeLayout 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" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="2000dp"
android:orientation="vertical"
android:weightSum="8" >
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:background="#880000" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:background="#008800" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#000088" />
</LinearLayout>
</ScrollView>
输出:
提前致谢
【问题讨论】:
-
如果你是父视图的高度,那你为什么不给分高度像 android:layout_height="665dp"
-
嗯!因为我将来会根据屏幕尺寸(手机/平板电脑)更改这个 2000
标签: android android-layout android-linearlayout android-scrollview