0

固定岗位。

所以我有这两张图片,我想让它居中,下一张再次居中,这样当我将它加载到其他设备上时它会正确对齐。它工作得很好但我知道尺寸会因密度等而异。由于手机屏幕尺寸不同,我似乎无法在中间正确对齐背景。那么我应该做的最好的方法是什么?

第一个背景是设计,盒子一个。较暗的将是默认设置,其中将替换为我从相机拍摄的照片。

适用于我的手机尺寸的所需结果:http: //puu.sh/4XcuZ.jpg

问题图片: http: //puu.sh/4Xcsk.jpg

知道如何使它们适合,以便它们可以在任何设备上正常工作吗?我的 UI 太乱了,因为我正试图相应地适应它们。我读到我应该使用 Dp、fill_parent 等,但这有点令人困惑。有小费吗?就像我想要完成的第一件事是让我的第一个背景在加载到任何设备时具有均匀的大小,然后是第二个背景。

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
     android:background="@drawable/test"
     android:padding="10dp">



<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
     >
<RelativeLayout
    android:id="@+id/RelativeLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">



 <LinearLayout
    android:layout_width="400dp"
    android:layout_height="400dp"
    android:orientation="horizontal"
     >

        <ImageView

        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerVertical="true"
         android:scaleType="fitCenter"
        android:src="@drawable/firstbackground" />


        </LinearLayout>

        <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_centerVertical="true"
     >



    <LinearLayout
    android:layout_width="290dp"
    android:layout_height="336dp"
    android:orientation="horizontal"
  android:layout_centerVertical="true"

     >
  <ImageView
        android:@+id/ivReturnImage
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerVertical="true"
         android:scaleType="fitCenter"
        android:src="@drawable/secondbackground" />



    </LinearLayout>
    </LinearLayout>


</RelativeLayout>


<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dp"

    >    

    <ImageButton
        android:id="@+id/ibTakePic"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
           android:background="@drawable/take_picture" />


        <ImageButton
        android:id="@+id/ibRotateImage"
        android:layout_width="50dp"
        android:layout_height="45dp"
        android:layout_gravity="center"
           android:background="@drawable/object_rotate_left" />

        <ImageButton
        android:id="@+id/ibOpenImage"
        android:layout_width="55dp"
        android:layout_height="45dp"
        android:layout_gravity="center"
           android:background="@drawable/picture_book" />

             <ImageButton
           android:id="@+id/bSetWallpaper"
           android:layout_width="40dp"
           android:layout_height="40dp"
           android:layout_gravity="center"
           android:background="@drawable/preferences_desktop_wallpaper"/>



                   <TextView
                   android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

       <ImageButton
           android:id="@+id/bSaveImage"
           android:layout_width="50dp"
           android:layout_height="45dp"
           android:layout_gravity="center"
           android:padding="10dp"
           android:background="@drawable/document_save"/>

</LinearLayout>




</LinearLayout>

 <SlidingDrawer
     android:id="@+id/slidingDrawer1"
     android:layout_width="273dp"
     android:layout_height="550dp"
     android:content="@+id/content"
     android:handle="@+id/handle"
     android:topOffset="390dp" >

    <RelativeLayout
         android:id="@+id/handle"
         android:layout_width="wrap_content"
         android:layout_height="48dp" >

         <ImageView
             android:layout_width="180dp"
             android:layout_height="33dp"
             android:layout_alignParentBottom="true"
             android:layout_centerHorizontal="true"
             android:scaleType="centerCrop"
             android:src="@drawable/handle" />
     </RelativeLayout>

     <LinearLayout
         android:id="@+id/content"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:background="@drawable/drawer_background"
         android:orientation="vertical" >

         <TextView
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:text="Please select a filter" />

     <Spinner
         android:id="@+id/spinner1"
         android:layout_width="fill_parent"
         android:layout_height="41dp" />

         <Spinner
             android:id="@+id/spinner2"
             android:layout_width="match_parent"
             android:layout_height="41dp" />

         <LinearLayout
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:orientation="horizontal"
             android:padding="10dp" >

             <Button
                 android:id="@+id/bImplement"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="Implement Effect" />

             <Button
                 android:id="@+id/bOriginal"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="Revert to original" />
         </LinearLayout>
         </LinearLayout>
     </SlidingDrawer>

    </FrameLayout>
4

1 回答 1

1
see if u want to go with layout format that you have to make some drawable like 
1.drawable-hdpi
2.drawable-large
3.drawable-ldpi
4.drawable-xhdpi
5.drawable-xlarge-mdpi
6.drawable-xxhdpi

and make all layout respectively then your app is going fine on any mobile tablet blue stack AOC android device 

if u go with java code then 
    int density= getResources().getDisplayMetrics().densityDpi;

    if(density==DisplayMetrics.DENSITY_HIGH)
                            System.out.println("Density is high");

                        if(density==DisplayMetrics.DENSITY_XXHIGH)
                            System.out.println("Density is xxhigh");

                        if(density==DisplayMetrics.DENSITY_XXXHIGH)
                            System.out.println("Density is xxxhigh");

                        if(density==DisplayMetrics.DENSITY_TV)
                            System.out.println("Density is Tv"); 

if(widthDp==600)
                    {
                        imageWidth =  ;
                        imgHeight =  ;
                        margin =  ;
                    }
                    else if (widthDp==720)
                    {

                    }
                    else if(density==DisplayMetrics.DENSITY_XHIGH)
                    {
                        imageWidth =  ;
                        imgHeight =  ;
                        margin =  ;
                    }
                    else if(density==DisplayMetrics.DENSITY_LOW)
                    {
                        imageWidth =  ;
                        imgHeight =  ;
                        margin =  ;
                    }
                    else if(density==DisplayMetrics.DENSITY_MEDIUM)
                    {
                        imageWidth =  ;
                        imgHeight =  ;
                        margin =  ;
                    }
                    else
                    {
                        imageWidth =  ;
                        imgHeight =  ;
                        margin =  ;
                    }

do what ever way u like :)
BEST OF LUCK DUDE :)
于 2013-10-23T08:56:41.440 回答