开发者

How can I get my Android Gallery to fit within my Relative Layout?

I'm currently stuck on my landscape layout. I am implementing a Gallery, and would like it to fit the relative layout's height, and wrap the content via the width. I tried scaleType centerInside, messing with different types of layout_height/width.

Here's where the relevant part of my XML looks like (I apologize for the lack of formatting):

<?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"开发者_StackOverflow
 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"
/>

Here is the image of the cutoff.


I don't believe you can apply scaleType to a Gallery: looking at http://developer.android.com/reference/android/widget/Gallery.html I don't see scaleType as one of the supported attributes.

EDIT: You should apply the scaleType attribute on the ImageView you are putting in the Gallery.


I don't think wrap_content works well with the width of a Gallery view.

Instead use android:layout_toRightOf, it will ensure that the Gallery doesn't extend into the area of your textviews. The following code is an example, but I have not tested it.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜