我有我的滾動型這個令人沮喪的問題裏面,這裏是我的層次:安卓:與重量的LinearLayout滾動型
ScrollView (Vertical)
LinearLayout (Vertical)
ImageView weight= 0.5
Whatever weight= 0.1
Whatever weight= 0.2
Whatever weight= 0.2
如果我刪除了滾動(並讓的LinearLayout作爲主項),這可以正常使用任何圖像:圖像佔用了屏幕大小的50%,而其他視圖則佔用其餘的視圖。
但是,當ScrollView在這裏時,如果我的圖像太高,「weight」參數將被完全忽略:圖像將盡其所能去適應屏幕寬度,然後顯然會過高並且需要更多比屏幕的50%。編輯:實際上,所有的「權重」屬性似乎忽略:
我想要的線性佈局,以配合得非常完美,而無需滾動。那可能嗎 ?我試圖改變一些圖像選項(scaleType,adjustViewBounds),但我沒有設法得到我想要的。
這裏是整個XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:adjustViewBounds="true"
android:src="@drawable/testing" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:text="I'M A TEST" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:text="I'M A TEST" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:text="I'M A TEST" />
</LinearLayout>
</ScrollView>
注:我需要的滾動型,因爲我使用的是這樣一個PullToRefresh滾動型
出於好奇,如果你不想滾動,爲什麼你需要scrollview? – wanpanman
基本上這^。滾動查看沒有維度,它可以是無限的。你期望你的imageview有50%是什麼?如果它是線性佈局,它知道。 ScrollView佔用儘可能多的空間,因爲它需要。 – Vucko
這看起來不對。看看https://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html這可能是你需要的。 – tynn