我正在使用背景作为布局,其中性别框已嵌入背景中。我打算放置两个包含男性和女性图像的小型ImageView。我在图形布局中拖放了两个图像,因此xml文件显示marginTop和marginLeft属性。问题是,如果我尝试以不同的分辨率运行我的应用程序,图像将不会放在确切的位置。如何解决这个问题?
这是性别框的图像,它是背景的一部分。它将有两个男性和女性的图像(图像视图除外)。这个性别框嵌入在布局背景中。
答案 0 :(得分: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