[英]could not scroll content in relative or linear layout
我在頂部相對布局中有三個線性布局
第三,它有一個gridview
情況1:當listview從服務器加載內容時,它占據了全屏,所以我看不到它在線性布局下面
情況2:當我在最高視圖上應用滾動視圖時,內部列表視圖中的對象會正確滾動。 嵌套的scrollview不起作用。
我想嘗試的另一個想法是:我想顯示listview的每個內容,以便不需要滾動listview內容(滾動頂部的實際布局可能顯示lisview的內容)..但不知道如何實現此目的布局以及它是否有效。 如何在一個屏幕上查看所有三個線性布局的內容 ? 請幫助您,將不勝感激。
這是布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="TeamDetails">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="@drawable/cardview_shadow"
android:elevation="2dp"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:text="Squad"
android:textColor="@color/primaryDarkColor"
android:textStyle="bold" />
<GridView
android:id="@+id/players_list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="120dp"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="auto_fit"
android:padding="10dp"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="@drawable/cardview_shadow"
android:elevation="2dp"
android:orientation="vertical"
android:visibility="visible">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:text="Fixtures"
android:textColor="@color/primaryDarkColor"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:layout_weight=".28"
android:background="@drawable/menu_bg"
android:elevation="1dp"
android:gravity="right|end"
android:orientation="horizontal"
android:visibility="visible">
<Spinner
android:id="@+id/spinner"
android:layout_width="243dp"
android:layout_height="11dp"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:background="@android:color/transparent"
android:gravity="center"
android:spinnerMode="dialog" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:src="@drawable/drop"
android:visibility="visible" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/squad_containerr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:elevation="2dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="@drawable/cardview_shadow"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:text="Detail"
android:textColor="@color/primaryDarkColor"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
請將布局的高度初始化為0並分配weight屬性,以便它們可以將整個屏幕划分為所有布局。
示例:如果將兩個布局的權重初始化為1,將最后一個布局的權重初始化為2,則整個屏幕將分為4部分,並且隨着權重的編號,該部分將分配給每個視圖,但是由於重量是2。
ScrollView
最多可以容納一個ChildView,因此將頂部的RelativeLayout
替換為ScrollView
並在ScrollView下方添加其他布局。在ScrollView下方添加LinearLayout
並將ListView
放入其中。
像這樣使用weight屬性:(將weight值更改為所需的UI分區比率)
<LinearLayout
android:weightSum="3"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_weight="1"
android:layout_height="0dp"
android:layout_width="match_parent">
........
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_height="0dp"
android:layout_width="match_parent">
.........
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_height="0dp"
android:layout_width="match_parent">
......
</LinearLayout>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.