如何让我的Android图库适合我的相对布局?

时间:2011-06-30 18:11:14

标签: android gallery

我目前仍然坚持我的风景布局。我正在实现一个Gallery,并希望它适合相对布局的高度,并通过宽度包装内容。我尝试了scaleType centerInside,搞乱了不同类型的layout_height / width。

这是我的XML相关部分的样子(我为缺乏格式而道歉):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_height="fill_parent"
 android:layout_width="fill_parent"
 android:padding="10dip"
 android:orientation="vertical">

 <RelativeLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
    android:layout_width="fill_parent">

<Gallery xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gallery"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:scaleType="centerInside"
/>

这是image  截止。

2 个答案:

答案 0 :(得分:1)

我不相信你可以将scaleType应用于图库:查看http://developer.android.com/reference/android/widget/Gallery.html我没有看到scaleType是受支持的属性之一。

编辑:你应该在你放入画廊的ImageView上应用scaleType attribute

答案 1 :(得分:0)

我认为wrap_content不适用于Gallery视图的宽度。

而是使用android:layout_toRightOf,它将确保Gallery不会延伸到textviews的区域。以下代码是一个示例,但我还没有对其进行测试。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_height="fill_parent"
 android:layout_width="fill_parent">

<LinearLayout
android:id="@+id/right_side"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true">

*put your textviews here*
</LinearLayout>

<Gallery 
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_toLeftOf="@id/right_side"
/>


</RelativeLayout>