2013-10-22 24 views
0

我创建了小的,正常的,大的和xl的布局,当我运行代码时,我做了 这是两个都是正常屏幕尺寸时的结果。 如果我解决了其中一个得到了混乱,反之亦然。他们是解决这个问题的另一种方式,或者如何解决这个问题Android和支持Multiscreen的显示图像问题

HTC一个V- HTC one V

三星S3 Samsung 3

用于正常布局的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/background1" 
    android:gravity="fill_vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/seekBar1" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/pumpkin" /> 

    <ImageButton 
     android:id="@+id/imageButton2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="500dp" 
     android:layout_marginTop="150dp" 
     android:background="@null" 
     android:src="@drawable/righteyeoff" /> 

    <SeekBar 
     android:id="@+id/seekBar1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView1" 
     android:layout_alignParentBottom="true" 
     android:thumb="@drawable/skull" /> 

    <ImageButton 
     android:id="@+id/imageButton1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="350dp" 
     android:layout_marginTop="150dp" 
     android:background="@null" 
     android:src="@drawable/lefteyeoff" /> 

</RelativeLayout> 

回答

0

您也可以使用框架/线性布局。尽管如此,我仍然在使用dp,但数字越来越小,这就减少了你所看到的巨大差异。 我希望你仍然有这个想法,我没有你的图像使用如此刚刚使用的颜色。在这个例子中,你应该使用wrap_content而不是设置的宽度/高度。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:padding="20dp"> 
    <LinearLayout android:id="@+id/pumpkin" android:layout_width="200dp" android:layout_height="200dp" android:layout_gravity="center" android:gravity="center" android:background="@android:color/black"> 
     <ImageView android:id="@+id/leftEye" android:orientation="horizontal" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginBottom="30dp" android:layout_marginRight="20dp" android:src="@android:color/holo_orange_dark" /> 
     <ImageView android:id="@+id/rightEye" android:orientation="horizontal" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginBottom="30dp" android:layout_marginLeft="20dp" android:src="@android:color/holo_orange_dark" /> 
    </LinearLayout> 
    <SeekBar android:id="@+id/seekBar1" android:layout_gravity="bottom" android:layout_width="match_parent" android:layout_height="wrap_content" /> 
</FrameLayout> 
0

我已经发现,这是很困难的,在每个的顶部放置的物体/图像其他使用Android。

我会把事情放在绝对中心。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/RelativeLayout01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

对于图像我会使用

<ImageView 
    android:id="@+id/main_pic" 
    android:layout_width="xxdip or wrap_content " 
    android:layout_height="xxdip or wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true"> 

,并把一些在他人之上。也许眼睛(仍然在相对布局)在鼻子上方的线性布局。

祝你好运!

+0

您不能定义一个空layout_width /身高的形象图,这是非法的 – JoxTraex

+0

我没有写这直接复制。 user1975060可以用他或她想要的任何倾角或填充来填充它 – heLL0