-1

我正在使用背景作为性别框已经嵌入背景的布局。我打算放置两个具有 Male 和 female 图像的小 ImageViews 。我在图形布局中拖放了两个图像,因此 xml 文件显示 marginTop 和 marginLeft 属性。问题是,如果我尝试以不同的分辨率运行我的应用程序,图像将不会被放置在确切的位置。如何解决这个问题?

这是作为背景一部分的性别框的图像。它将有男性和女性的两个图像(除了图像视图)。这个性别框嵌入在布局背景中。

在此处输入图像描述

4

1 回答 1

1
Try this snippet of code in you xml file. Hope it will help you 

<LinearLayout
        android:id="@+id/ll_gender"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_centerInParent="true" >

        <ImageView
            android:id="@+id/iv_male"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/male" />

        <ImageView
            android:id="@+id/iv_female"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/female" />

    </LinearLayout>

You can adjust them in your existing xml file accordingly. You can set properties of this linear layout in respect of other layouts in your code so it will not destroy your design on max no of devices. Use Relative layout as the parent of linear layout so you can adjust it more easily or paste your complete xml file code if you still face problem.
You can use different folders for different screens

    res/drawable-mdpi/my_icon.png        // bitmap for medium density
    res/drawable-hdpi/my_icon.png        // bitmap for high density
    res/drawable-xhdpi/my_icon.png       // bitmap for extra high density
于 2013-12-12T10:11:36.947 回答