[英]layout design with scroll view and linear layout
我絕對是android開發的初學者,並且正在開發具有滾動視圖和線性布局的UI。 這是我的代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:clipToPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_green_light"
android:theme="?attr/actionBarTheme"
android:minHeight="?attr/actionBarSize"
android:id="@+id/dashboardToolbar"
android:layout_weight="0.04" />
<TextView
android:text="Manage Activities"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:layout_weight="9.78"
android:textAlignment="center"
android:textSize="30sp"
android:layout_margin="21dp"
android:fontFamily="cursive"
android:textColor="@android:color/holo_orange_light"
android:textStyle="normal|bold" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="470dp"
android:weightSum="1">
<LinearLayout
android:orientation="vertical"
android:layout_margin="4dp"
android:background="@color/green"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="120dp"></LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_margin="4dp"
android:background="@color/deeppurple"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="120dp">
</LinearLayout>
</LinearLayout>
<!-- second row -->
<!-- second row- -->
</LinearLayout>
</ScrollView>
</LinearLayout>
我得到兩個水平的線性布局,沒有任何問題。 我要使第三個線性布局出現在第一個布局的底部。 基本上我正在為我的應用程序開發儀表板UI,我只想制作2列和5行的線性布局矩陣。 我已經在我的xml文件的第二行中添加了注釋,如果有人可以幫助我提供xml代碼或解決該問題的想法,我非常感謝。
您應該只能夠復制:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="470dp"
android:weightSum="1">
<LinearLayout
android:orientation="vertical"
android:layout_margin="4dp"
android:background="@color/green"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="120dp"></LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_margin="4dp"
android:background="@color/deeppurple"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="120dp">
</LinearLayout>
</LinearLayout>
放入垂直的LinearLayout中。 但是是看不見的問題嗎?
我看到您在ScrollView之后有第一個LinearLayout作為match_parent。 它應該是wrap_content,以使布局擴展到父級之外並且可以滾動。
一個不錯的技巧是為布局設置不同的背景顏色,以便您可以查看每個布局的大小並檢查寬度/高度是否有誤。
編輯:我看到您在水平LinearLayout中具有android:layout_height =“ 470dp”,在其子級中具有android:layout_height =“ 120dp”。 我不知道它的外觀,但似乎有點奇怪,也許您應該將Layouts設置為不同的背景顏色,以確保這是您想要的尺寸。
請嘗試使用此xml代碼來實現所需的布局
碼
<?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="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/dashboardToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:background="@android:color/holo_green_light"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".08"
android:gravity="center">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="cursive"
android:text="Manage Activities"
android:textAlignment="center"
android:textColor="@android:color/holo_orange_light"
android:textSize="30sp"
android:textStyle="normal|bold" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".02" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".14">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_margin="4dp"
android:layout_weight="0.5"
android:background="@color/colorPrimary"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_margin="4dp"
android:layout_weight="0.5"
android:background="@color/colorAccent"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".02" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".14">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_margin="4dp"
android:layout_weight="0.5"
android:background="@color/colorPrimary"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_margin="4dp"
android:layout_weight="0.5"
android:background="@color/colorAccent"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".02" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".14">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_margin="4dp"
android:layout_weight="0.5"
android:background="@color/colorPrimary"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_margin="4dp"
android:layout_weight="0.5"
android:background="@color/colorAccent"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".02" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".14">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_margin="4dp"
android:layout_weight="0.5"
android:background="@color/colorPrimary"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_margin="4dp"
android:layout_weight="0.5"
android:background="@color/colorAccent"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".02" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".14">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_margin="4dp"
android:layout_weight="0.5"
android:background="@color/colorPrimary"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_margin="4dp"
android:layout_weight="0.5"
android:background="@color/colorAccent"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".1" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
屏幕截圖
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.