开发者

ImageViews inside of RelativeLayout, that is nested inside of a LinearLayout

My goal is to display 6 images (1 image, 6 times) across one line on my screen. My approach was to nest a RelativeLayout inside of a LinearLayout. My issue is that when I'm in 'portrait' mode, I cannot see all of my images. The more I resize my image, the more of the images I can fit, But I'm at a point where I do not 开发者_C百科want it to be any smaller. I assumed that by default, it would just wrap what it can't fit, but that doesnt seem to be the case. Theres no auto re-size to fit? Also, how can I manually decide how much space is between each image? Thanks!


Basically, you need to provide two different xml files for your app, one for portrait, once for landscape as per: Providing Resources. android will pick the proper xml file based on orientation.

and this ImageView.ScaleType explains the different scaling styles

Here is what I would suggest:

res/layout-land/main.xml

<?xml version="1.0" encoding="utf-8" ?> 
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">
    <ImageView
        android:id="@+id/debris_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitCenter"
        android:weight="1"
        android:src="@drawable/image1"
    </ImageView
    ... repeat 5 more times ...
</LinearLayout>

the weight element should make them all fit but there might be a conflict with scaleType. anyway that should do it for your landscape, for portrait, you could either make it so there were two rows of images, or you could use a horizontalScrollView as below:

res/layout-port/main.xml

<?xml version="1.0" encoding="utf-8" ?>
<HorizontalScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">        
        <ImageView
            android:id="@+id/debris_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="fitCenter"
            android:weight="1"
            android:padding="15dp"
            android:src="@drawable/image1"
        </ImageView
        ... repeat 5 more times ...
    </LinearLayout>
</HorizontalScrollView>    

really, you could prolly just use the portrait main.xml as your only layout file and just have it be horizontally scrolling regardless of orientation. you might need to change some times in the portrait main.xml as i am at work and im not sure how well weight works with horizontalScrollView

as far as the space between each element, you would use android:padding like i have above.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜