2017-07-15 64 views
0

我試着做Android的手電筒應用程序(作爲一個絕對的初學者)按鈕置於相對保持背景圖像

的概念是讓鋼鐵俠的胸部光作爲閃光UI切換按鈕。

我設置鐵人作爲背景ImageView。並將胸部照片設置爲按鈕的圖像src。

問題是,在不同的屏幕尺寸下,按鈕的對齊方式會發生變化,您可以在下面的屏幕截圖中看到。 這就是它的樣子:

enter image description here

按鈕時,屏幕尺寸改爲流離失所:

enter image description here

如果有人可以幫助我,我怎麼能解決這個問題,它會很棒。

我的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> 

回答

0

的問題是,你正在設計具體到一個設備/屏幕布局。

從docs-

Android支持多種配置限定符,可讓您 控制基於當前設備屏幕的 特性的系統如何選擇你的替代資源。配置 限定符是一個字符串,您可以將其附加到您的Android項目的 中的資源目錄,並指定內部設計的 資源的配置。

請參閱Different values folders in android關於如何使不同的值/ dimens.xml適合不同的屏幕。

因此,創建不同的價值觀文件夾並選擇文件 - link

0

什麼父母佈局是您使用? 如果使用RelativeLayout,則必須相互制作按鈕