【问题标题】:How can I get my Android Gallery to fit within my Relative Layout?如何让我的 Android Gallery 适合我的相对布局?
【发布时间】:2011-07-01 02:33:11
【问题描述】:

我目前卡在横向布局上。我正在实现一个画廊,并希望它适合相对布局的高度,并通过宽度包装内容。我尝试了 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 截止日期。

【问题讨论】:

    标签: android gallery


    【解决方案1】:

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

    编辑:您应该将scaleType attribute 应用于您要放入画廊的 ImageView。

    【讨论】:

      【解决方案2】:

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

      改为使用 android:layout_toRightOf,它将确保 Gallery 不会扩展到您的 textview 区域。下面的代码是一个例子,但我没有测试过。

      <?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>
      

      【讨论】:

        猜你喜欢
        • 2015-02-06
        • 2014-02-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-19
        • 1970-01-01
        • 1970-01-01
        • 2021-11-23
        相关资源
        最近更新 更多