2011-03-09 104 views
0

我的目标是在屏幕上的一条线上显示6个图像(1个图像,6次)。我的方法是在LinearLayout中嵌套一个RelativeLayout。我的问题是,当我处于“肖像”模式时,我看不到所有的图像。我调整图像的尺寸越大,我可以适应的图像就越多,但是我不希望它变得更小。我认为,默认情况下,它会包装它不适合的东西,但似乎并非如此。 Theres没有自动重新调整大小以适应?另外,如何手动确定每张图像之间有多少空间?谢谢!RelativeLayout中的ImageViews嵌套在LinearLayout中

回答

0

基本上,您需要为您的应用程序提供两个不同的xml文件,一个用于纵向,一个用于横向格式:Providing Resources。 android会根据方向选择合适的xml文件。

ImageView.ScaleType解释了不同的缩放风格

这里是我的建议:

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> 

weight元素应该让他们都保持健康,而且有可能与scaleType冲突。无论如何应该为你的风景做,人像,你既可以使它所以有图像的两行,或者你也可以如下使用horizontalScrollView

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>  

真的,你可以prolly只使用肖像main.xml作为您唯一的布局文件,并且无论方向如何都可以水平滚动。您可能需要更改一些时间在肖像main.xml因为我在工作和林不知道如何与weighthorizontalScrollView

工作尽可能的每个元素之间的空间,你可以使用android:padding像我上面都有。

相关问题