【发布时间】:2011-10-31 23:13:13
【问题描述】:
我是 android 开发的新手,在让布局显示我想要的方式时遇到了一些问题。 基本上我想要的是四个包含带有标签的图像的横向滚动视图。直到运行时才知道图像的数量。我希望侧滚动视图可以缩放到不同的大小。
现在,我的设置如下所示: 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" />
查看项目.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" />
HorizontalScrollViews 内部还有一个 LinearLayout
<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 实例化了一堆这些视图项,将它们添加到 LinearLayout (horizll),然后将它们膨胀并添加到 HorizontalScrollView。 (所有这些都在 onCreate() 中完成)
代码几乎按预期工作。我有四个横向滚动列表,它们的高度对应于它们的重量。但是,其中的图像会停留在默认大小,换句话说,它们不会随着 HorizontalScrollView 的高度而缩放。
我做错了什么?
提前感谢您的帮助
【问题讨论】: