我很新的android開發,我一直有一些問題讓我的佈局顯示我想要的方式。 基本上我想要的是包含帶標籤圖像的四個橫向滾動視圖。直到運行時才能知道圖像的數量。我希望橫向滾動視圖可以縮放到不同的大小。Scaling ImageView裏面的HorizontalScrollView
眼下,設置我有看起來像這樣: 的main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff" android:id="@+id/build">
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_weight="1"
android:layout_height="0dp" android:background="#ddd" android:id="@+id/ahsv" />
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_weight="1"
android:layout_height="0dp" android:background="#ddd" android:id="@+id/ihsv" />
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_weight="2"
android:layout_height="0dp" android:background="#ddd" android:id="@+id/mhsv" />
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_weight="3"
android:layout_height="0dp" android:background="#ddd" android:id="@+id/rhsv" />
viewitem.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:background="#fff">
<ImageView android:id="@+id/image" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:scaleType="center" />
<TextView android:id="@+id/title" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:textColor="#000"
android:layout_gravity="center_horizontal|bottom" />
還有一個LinearLayout進入HorizontalScrollViews
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#fff"
android:id="@+id/horizll"/>
此時我的代碼只是使用實例化這些LayoutInflator的viewitems一堆,將它們添加到的LinearLayout(horizll),這是充氣並添加到HorizontalScrollView。 (所有這些都在onCreate()中完成)
代碼幾乎按照預期工作。我有四個側面滾動列表,其高度與其權重相對應。但是,這些內部的圖像會停留在其默認大小上,換句話說,它們不會使用HorizontalScrollView的高度進行縮放。
我在做什麼錯?
在此先感謝您的幫助
我不能讓它與最小寬度和高度一起工作,但我在ImageView上使用了setLayoutParams(),並且對我有用。 – richy