作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 android 开发的新手,在让我的布局以我想要的方式显示时遇到了一些问题。基本上我想要的是四个横向 ScrollView ,其中包含一个带标签的图像。直到运行时才知道图像的数量。我希望横向 ScrollView 可以缩放到不同的大小。
现在,我的设置看起来像这样:主.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" />
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 实例化了一堆这些 View 项,将它们添加到 LinearLayout (horizll),后者被膨胀并添加到 HorizontalScrollView。 (所有这些都在 onCreate() 中完成)
代码几乎按预期工作。我有四个横向滚动列表,它们的高度与其权重相对应。但是,其中的图像固定为默认大小,换句话说,它们不随 HorizontalScrollView 的高度缩放。
我做错了什么?
在此先感谢您的帮助
最佳答案
好吧,我终于明白了。我最终在 SO 上看了很多,并在 using ViewTreeObserver 上发现了一个问题.设置适当的 VTO 后,我可以指定 FrameLayout 的最小宽度和高度。有点 hackish,但它可以完成工作。
关于android - 在 HorizontalScrollView 内部缩放 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7918106/
我是一名优秀的程序员,十分优秀!