2013-02-19 57 views
0

我想在相应的图像视图中放置两个图像,以使它们占据整个屏幕。到目前为止我只在这里得到:((要添加被测试的器件我使用S3)放置两个图像占据整个屏幕

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

<ImageView 
    android:id="@+id/white" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:onClick="onClick" 
    android:src="@drawable/up" /> 

    <ImageView     
    android:id="@+id/blue" 
    android:layout_height="fill_parent" 
      android:layout_width="fill_parent" 
      android:src="@drawable/blue" 
      android:onClick="onClick" 
      android:layout_below="@id/white"/> 

</RelativeLayout> 

的图像是1080×1920,并调整为屏幕,问题是要么低于图像被不正确地缩放或他们不正确连接我有一个在顶部黑色区域和底部

我很抱歉,但该图片的大小相同的不

+0

看看这里:http://stackoverflow.com/questions/14773039/how-to-put-50-for-width – 2013-02-19 16:56:21

回答

1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:weightSum="2" > 

<ImageView 
    android:id="@+id/white" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:onClick="onClick" 
    android:src="@drawable/up" /> 

<ImageView 
    android:id="@+id/blue" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:onClick="onClick" 
    android:src="@drawable/blue" /> 

</LinearLayout> 
+0

高度应该是0 – Pragnani 2013-02-19 16:55:52

+0

图像是不一样的大小,我应该添加此之前。 – 2013-02-19 16:58:45

+0

这不是您可以设置图像的缩放类型的问题。如果你愿意,你可以根据你的意愿设置高度值。另外一个添加设置的线性布局的方向类型 – Triode 2013-02-19 17:00:46

0

您应该使用的LinearLayout与layout_weight集:。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
<ImageView 
    android:id="@+id/white" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:onClick="onClick" 
    android:src="@drawable/up" /> 

<ImageView     
    android:id="@+id/blue" 
    android:layout_height="0dp" 
    android:layout_width="fill_parent" 
    android:layout_weight="1" 
    android:src="@drawable/blue" 
    android:onClick="onClick" 
    android:layout_below="@id/white"/> 
</LinearLayout> 

对于尺度问题,我建议你寻找到scaleType

+0

它的作品谢谢:) – 2013-02-19 22:39:08

2

您可以通过添加weightSum实现这一目标。更多help.please添加注释 enter image description here :替换此XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity1" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:weightSum="1" > 

     <ImageView 
      android:id="@+id/white" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight=".5" 
      android:onClick="onClick" 
      android:src="@drawable/up" /> 

     <ImageView 
      android:id="@+id/blue" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_below="@id/white" 
      android:layout_weight=".5" 
      android:onClick="onClick" 
      android:src="@drawable/blue" /> 
    </LinearLayout> 

</RelativeLayout> 

它会是什么样子的。

+0

这也工作谢谢:) – 2013-02-19 22:40:33