2017-07-15 59 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,则必须相互制作按钮