ÀÖÓãµç¾º

½ÌÓýÐÐÒµA¹ÉIPOµÚÒ»¹É£¨¹ÉƱ´úÂë 003032£©

È«¹ú×Éѯ/ͶËßÈÈÏߣº400-618-4000

AndroidÅàѵʵս½Ì³ÌÖ®ÆÁÄ»ÊÊÅä

¸üÐÂʱ¼ä:2015Äê12ÔÂ28ÈÕ13ʱ38·Ö À´Ô´:ÀÖÓã²¥¿ÍAndroidÅàѵѧԺ ä¯ÀÀ´ÎÊý:

ʲôÊÇÊÊÅä

ÊÊÅä ¼´µ±Ç°Ó¦ÓÃÔÚÏàͬµÄÊÖ»úÉÏÃæÏÔʾÏàͬµÄЧ¹û¡£
 
ÊÊÅäǰÐèÒªÊ×ÏÈÈ·¶¨µ±Ç°ÊÖ»úËùÊôÏñËØÃܶÈÀàÐÍ(È磺xhdpi¡¢hdpi¡¢mdpiµÈ)£¬ÏÂÃæÒÔ»ªÎªG700¡¢Ä£ÄâÆ÷ΪÀý£¬½²½âÈçºÎ¼ÆËãÏñËØÃܶÈ¡£
°¸ÀýÒ»£º
ÊÖ»úÐͺÅ£ºG700
ÊÖ»ú·Ö±æÂÊ£º1280*720 (×¢£ºÊÖ»úÁ½¸öÖ±½Ç±ßÉÏ·Ö±ð·ÅÖÃÁË1280¼°720¸öÏñËØµã)
ÊÖ»ú³ß´ç´óС£º5Ó¢´ç(ÊÖ»úб±ß³¤¶È)

¼ÙÉèa£¬b·Ö±ðΪÁ½¸öÖ±½Ç±ß£¬cΪб±ß£¬Óɹ´¹É¶¨Àí¿ÉµÃ³ö¼ÆË㷽ʽ£ºsqrt(a*a+b*b)/c
¼ÆËã½á¹û£ºsqrt(1280*1280+720*720)/5 ≈ 293.72dpi
¸ù¾Ýgoogle¹Ù·½ÎĵµËµÃ÷µÃ³ö£¬µ±Ç°ÊÖ»ú×î½Ó½ü320dpi£¬Ôò½«Æä¹éÄÉÔÚxhdpiÊÖ»ú·¶Î§ÄÚ£¬
¼´1dp=2px£»
 
°¸Àý¶þ£º
ÊÖ»úÐͺţºÄ£ÄâÆ÷
ÊÖ»ú·Ö±æÂÊ£º800*480(×¢£ºÊÖ»úÁ½¸öÖ±½Ç±ßÉÏ·Ö±ð·ÅÖÃÁË800¼°480¸öÏñËØµã)
ÊÖ»ú³ß´ç´óС:3.7Ó¢´ç(ÊÖ»úб±ß´óС)

¼ÆËã½á¹û£ºsqrt(800*800+480*480)/3.7 ≈ 252.15dpi
¸ù¾Ýgoogle¹Ù·½Îĵµ(ͼ1-1)µÃ³ö£¬µ±Ç°ÊÖ»ú½Ó½ü240dpi£¬Ôò½«Æä¹éÄÉÔÚhdpiÊÖ»ú·¶Î§ÄÚ£¬
¼´1dp=1.5px¡£
      
°´ÕÕÒÔÉϼÆË㷽ʽ£¬´óÖ¿ÉÒÔ½«Êг¡ÉϵÄÊÖ»ú»®·ÖΪ5¸öÏñËØÃܶȵȼ¶£¬¾ßÌåÈçÏ£º
  1. ldpi£º120dpi£¬ÏñËØÃܶÈÓëdpת»»¹ØÏµÎª£º1dp = 0.75px
  2. mdpi£º160dpi £¬ÏñËØÃܶÈÓëdpת»»¹ØÏµÎª£º1dp = 1px
  3. hdpi£º240dpi£¬ÏñËØÃܶÈÓëdpת»»¹ØÏµÎª£º1dp = 1.5px
  4. xhdpi£º320dpi£¬ÏñËØÃܶÈÓëdpת»»¹ØÏµÎª£º1dp = 2px
  5. xxhdpi£º480dpi£¬ÏñËØÃܶÈÓëdpת»»¹ØÏµÎª£º1dp = 3px
 

ÈçºÎÊÊÅä

ÏÂÃæÒÔ»ªÎªÊÖ»úG700ºÍÄ£ÄâÆ÷µÄ¶Ô±È£¬½²½âÈçºÎ½øÐÐÆÁÄ»ÊÊÅ䣬¾ßÌ巽ʽÈçÏ£º

ÊÊÅ䷽ʽ1£ºÍ¼Æ¬ÊÊÅä

²»Í¬ÏñËØÃܶȵÄÊÖ»ú¼ÓÔØ¹¤³Ì×ÊÔ´Îļþ(res)Öв»Í¬×ÊԴͼƬ£¬ÒÔÊÖ»úG700ºÍÄ£ÄâÆ÷ΪÀý£¬Í¼Æ¬µÄ²¼¾Ö´úÂëÈçÏÂËùʾ£º
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/a"/>
</RelativeLayout>
 
ÈôʹÓÃG700(xhdpi)¼ÓÔØa.jpgÎļþ£¬¸ÃÎļþλÓÚres/drawable-xhdpiÎļþ¼ÐÏÂ,ÏÔʾЧ¹ûÈçÏ£º
 
ÈôʹÓÃÄ£ÄâÆ÷(hdpi)¼ÓÔØa.jpgÎļþ£¬¸ÃÎļþλÓÚres/drawable-hdpiÎļþ¼ÐÏÂ,ÏÔʾЧ¹ûÈçÏ£º

ÊÊÅ䷽ʽ2£ºdimens.xmlÎļþÊÊÅä

dimens.xml´æÔÚÓÚ¹¤³Ì×ÊÔ´(res)Îļþ¼ÐÖв»Í¬values(Èç:value-1280x720¡¢value-800x480)Îļþ¼ÐÏ£¬¿ÉÓÃÓÚÖ¸¶¨¿Ø¼þ´óС£¬²»Í¬ÏñËØÃܶÈÊÖ»ú¼ÓÔØ²»Í¬valuesÎļþ¼ÐϵÄdimens.xmlÎļþ£¬Ê¹Ó÷½Ê½ÈçÏ£º  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >
    <!-- ²»Í¬µÄÊÖ»ú¼ÓÔØ²»Í¬µÄdp -->
    <TextView
        android:background="#987654"
        android:layout_width="@dimen/width"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
</LinearLayout>
 
Ä£ÄâÆ÷(hdpi):¼ÓÔØdimens.xml×ÊÔ´Îļþ£¬Î»ÓÚres/value-800x480Îļþ¼ÐÏÂ
<resources>
    <dimen name="width">160dp</dimen>
</resources>
       ¸ù¾ÝÉÏÊöhdpi dpºÍpxµÄת»»¹ØÏµ1dp = 1.5px£¬Ôò160dp = 240px£¬µ±Ç°¿Ø¼þ¿í¶ÈÓ¦¸ÃλÓÚÆÁÄ»ÖмäλÖá£
G700(xhdpi):¼ÓÔØdimens.xml×ÊÔ´Îļþ£¬Î»ÓÚres/value-1280x720Îļþ¼ÐÏÂ
<resources>
    <dimen name="width">180dp</dimen>
</resources>
       ¸ù¾ÝÉÏÊöxhdpi ÖÐdpºÍpxµÄת»»¹ØÏµ1dp = 2px£¬Ôò180dp = 360px£¬µ±Ç°¿Ø¼þ¿í¶ÈÓ¦¸ÃλÓÚÆÁÄ»ÖмäλÖá£
 
G700£¨xhdpi£©ÏÔʾµÄͼƬЧ¹ûÈçÏÂËùʾ£º
Ä£ÄâÆ÷£¨hdpi£©ÏÔʾµÄͼƬЧ¹ûÈçÏÂËùʾ£º

ÊÊÅ䷽ʽ3£º²¼¾ÖÎļþÊÊÅä

²»Í¬·Ö±æÂʵÄÊÖ»ú£¬¼ÓÔØ²»Í¬µÄ²¼¾ÖÎļþÒÑ´ïµ½ÊÊÅäЧ¹û¡£´´½¨¶à¸ölayout(È磺layout-1280x720¡¢layout-800x480)Îļþ¼ÐÓÃÓÚ´æ·Å²»Í¬ÏñËØÃܶÈÊÖ»úËùÐè²¼¾ÖÎļþ¡£
 
Ä£ÄâÆ÷(hdpi):¼ÓÔØactivity_main.xml²¼¾ÖÎļþ,λÓÚres/layout-800x480Îļþ¼ÐÏ£º
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="800*480ÊÖ»ú»áÈ¥¼ÓÔØµÄ²¼¾ÖÎļþ" />
    </RelativeLayout>
 
G700(xhdpi):¼ÓÔØactivity_main.xml²¼¾ÖÎļþ,λÓÚres/layout-1280x720Îļþ¼ÐÏ£º
    <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1280*720ÊÖ»ú»áÈ¥¼ÓÔØµÄ²¼¾ÖÎļþ" />
    </RelativeLayout>
 
G700£¨xhdpi£©ÏÔʾµÄͼƬЧ¹ûÈçÏ£º
Ä£ÄâÆ÷£¨hdpi£©ÏÔʾµÄͼƬЧ¹ûÈçÏÂËùʾ£º

ÊÊÅ䷽ʽ4£ºjava´úÂëÊÊÅä

ͨ¹ýandroidÏàÓ¦api»ñÈ¡µ±Ç°ÊÖ»úµÄ¿í¸ßÏñËØÖµ£¬°´±ÈÀý·ÖÅäÆÁÄ»ÖпؼþµÄ¿í¸ßÒÔ´ïµ½ÊÊÅäЧ¹û£¬ÏÂÃæÊDz¼¾ÖºÍʵÏÖ¹¦ÄܵĺËÐÄ´úÂ룺      
       ²¼¾ÖÎļþ
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    <TextView
        android:id="@+id/tv"
        android:background="#000000"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
</RelativeLayout>
       activityÖÐoncreateºËÐÄ´úÂ룺
    TextView tv  = (TextView) findViewById(R.id.tv);
    //»ñÈ¡·â×°µ±Ç°ÊÖ»úÆÁÄ»ÐÅÏ¢¶ÔÏó£¬ÓÃÓÚ´æ·Å¿í¸ßÖµ
    DisplayMetrics metrics  = new DisplayMetrics();
    //¸øµ±Ç°ÆÁÄ»ÉèÖÿí¸ß
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    //»ñÈ¡¸ß¶È
    Constant.srceenHeight = metrics.heightPixels;
    //»ñÈ¡¿í¶È
    Constant.srceenWidth = metrics.widthPixels;
    Log.i(tag, "Constant.srceenHeight = "+Constant.srceenHeight);
    Log.i(tag, "Constant.srceenWidth = "+Constant.srceenWidth);
    //¿í¸ß¸÷Õ¼50%
    RelativeLayout.LayoutParams layoutParams = new
RelativeLayout.LayoutParams(
            (int)(Constant.srceenWidth*0.5+0.5),
            (int)(Constant.srceenHeight*0.5+0.5));
    tv.setLayoutParams(layoutParams);
G700£¨xhdpi£©ÏÔʾЧ¹ûÈçÏ£º
Ä£ÄâÆ÷£¨hdpi£©ÏÔʾЧ¹ûÈçÏ£º

ÊÊÅ䷽ʽ5£ºÈ¨ÖØÊÊÅä

ͨ¹ýandroidÌṩµÄ(È¨ÖØ)Ê£Óà¿Õ¼ä·ÖÅ䣬´ïµ½ÊÊÅäЧ¹û¡£²¼¾ÖÎļþÈçÏÂËùʾ:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context=".MainActivity" >
    <TextView
        android:background="#000000"
        android:layout_width="0dp"
        android:layout_weight="1"
         android:layout_height="match_parent"/>
    <TextView
        android:background="#123456"
        android:layout_width="0dp"
        android:layout_weight="1"
    android:layout_height="match_parent"/>
</LinearLayout>
 
G700£¨xhdpi£©ÏÔʾµÄͼƬЧ¹ûÈçÏÂËùʾ£º
Ä£ÄâÆ÷£¨hdpi£©ÏÔʾµÄͼƬЧ¹ûÈçÏÂËùʾ£º
 


±¾ÎİæÈ¨¹éÀÖÓã²¥¿ÍAndroidÅàѵѧԺËùÓУ¬»¶Ó­×ªÔØ£¬×ªÔØÇë×¢Ã÷×÷Õß³ö´¦¡£Ð»Ð»£¡
×÷ÕߣºÀÖÓã²¥¿ÍAndroidÅàѵѧԺ
Ê×·¢£ºhttp://www.itcast.cn/android/
0 ·ÖÏíµ½£º
ºÍÎÒÃÇÔÚÏß½»Ì¸£¡
¡¾ÍøÕ¾µØÍ¼¡¿¡¾sitemap¡¿