我試着做Android的手電筒應用程序(作爲一個絕對的初學者)按鈕置於相對保持背景圖像
的概念是讓鋼鐵俠的胸部光作爲閃光UI切換按鈕。
我設置鐵人作爲背景ImageView。並將胸部照片設置爲按鈕的圖像src。
問題是,在不同的屏幕尺寸下,按鈕的對齊方式會發生變化,您可以在下面的屏幕截圖中看到。 這就是它的樣子:
按鈕時,屏幕尺寸改爲流離失所:
如果有人可以幫助我,我怎麼能解決這個問題,它會很棒。
我的XML代碼,如果這將是有幫助:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
tools:context="example.flash.flash">
<!-- view for AdMob Interstitial Ad -->
<TextView
android:id="@+id/app_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="@string/interstitial_ad_sample"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/app_title"
android:layout_centerHorizontal="true"
android:text="@string/start_level"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/next_level_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/next_level" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/iron"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/colorBackground"
android:src="@drawable/onn"
android:scaleType="fitCenter"
android:layout_marginBottom="57dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_home_footer"></com.google.android.gms.ads.AdView>
</RelativeLayout>