2012-07-20 5 views
2

나는 시계 위젯을 개발했다. 많은 기기에서 괜찮아 보입니다. 모토로라 Xoom은 XLARGE 범주에 속하기 때문에 제외합니다. Android XLarge 화면을 다루는 방법은 무엇입니까?

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:background="#00000000" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

<AnalogClock android:id="@+id/AnalogClock" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:dial="@drawable/widgetclock" 
    android:hand_hour="@drawable/widgethour" 
    android:hand_minute="@drawable/widgetminute" /> 

    <!-- Time Row --> 
    <LinearLayout 
     android:id="@+id/lltimeheaderrow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"   
     android:orientation="horizontal" 
     android:layout_gravity="center|top" 
     android:layout_marginTop="45dp" 
     android:visibility="gone"> 

     <!-- TIME --> 
     <LinearLayout android:id="@+id/llTimeDefault" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:gravity="center"> 

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

      <TextView 
       android:id="@+id/HOUR" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/my_gray" 
       android:textStyle="bold" 
       android:textSize="15sp"/> 

      <TextView 
       android:id="@+id/MINUTE" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/my_gray" 
       android:textStyle="bold" 
       android:textSize="15sp" /> 
      </LinearLayout> 

      <TextView 
       android:id="@+id/AM_PM" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/my_gray" 
       android:textStyle="bold" 
       android:textSize="13sp" 
       android:padding="1dp" />       
     </LinearLayout> 
    </LinearLayout>  

    <!-- Calendar Graph --> 
    <LinearLayout 
     android:id="@+id/llCalGraph" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_gravity="center|left"  
     android:layout_marginLeft="45dp"> 
      <FrameLayout android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
       <ImageView 
        android:id="@+id/CalendarImg" 
        android:src="@drawable/calendar" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/>      
       <TextView android:id="@+id/DateDayG" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center|top" 
        android:layout_marginTop="3dp" 
        android:textSize="11sp" 
        android:textStyle="bold" 
        android:textColor="@color/my_gray" 
        android:shadowColor="@color/my_black" 
        android:shadowDx="1" 
        android:shadowDy="1" 
        android:shadowRadius="2"     
        ></TextView>  
       <TextView android:id="@+id/DateNoG" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_marginTop="5dp" 
        android:textSize="25sp" 
        android:textColor="@color/my_gray" 
        ></TextView>  
      </FrameLayout>    

    </LinearLayout>    

    <!-- BATTERY --> 
    <LinearLayout 
     android:id="@+id/llBattGraph" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_gravity="center|right" 
     android:layout_marginRight="45dp">    
      <FrameLayout android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
       <ImageView 
        android:id="@+id/BatteryImg" 
        android:src="@drawable/batt_00" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/> 
       <ImageView 
        android:id="@+id/BatteryFlashing" 
        android:src="@drawable/flashing" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_marginTop="13dp" 
        android:layout_marginLeft="2dp" 
        android:visibility="gone" />       
       <TextView 
        android:id="@+id/BatteryLevel" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textColor="@color/my_gray" 
        android:textSize="18sp" 
        android:layout_gravity="center" /> 


      </FrameLayout>    
    </LinearLayout>      

    <!-- Weather Row --> 
    <LinearLayout 
     android:id="@+id/llweatherrow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"   
     android:orientation="horizontal" 
     android:layout_gravity="center|bottom" 
     android:layout_marginBottom="45dp"> 

     <!-- WEATHER IMAGE --> 
     <LinearLayout 
      android:id="@+id/llWeatherImage" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:visibility="visible" 
      android:layout_gravity="center"> 

      <ImageView android:id="@+id/ivWeather" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/w3200" 
       /> 
     </LinearLayout> 

    </LinearLayout>  

</FrameLayout> 

는 기본적 위젯 4 개 요소를 갖는 clock.xml이다. 위, 아래. 왼쪽과 오른쪽 부분. 간단히 기본 레이아웃으로 FrameLayout을 사용하고 각 요소는 각 코너로 중력 45dp의 LinearLayout을 사용합니다.

위젯이 Xoom에서 보이는 방식입니다. 요소 위치가 빨간색 원에 있어야합니다.

  1. 내가 사용해야하는 최상의 레이아웃 조합은 무엇입니까? 제안 해 줄 수 있니?
  2. 이 레이아웃을 고집한다고 가정 해 봅시다. Xoom 장치의 대체 레이아웃은 어떻게 제공합니까? 나는

답변

3

가장 좋고 깔끔한 방법은 폴더 layout-xlarge을 생성하고 clock.xml가 포함에 때를로드 할 것이다 ... 레이아웃 초대형와 당김 - 초대형하지만 아무것도에 clock.xml을 넣어 시도 대상 장치의 레이아웃이 xlarge입니다.

그런 식으로

당신은 http://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts

또 다른 해결책이 값에 특정 45dp 또는 Xdp에있는 모든 크기를 가지고있는 개발자 문서에서 등 화면 크기, 밀도있어에 따라 다른 레이아웃을 만들 수 있습니다 폴더에있는 파일 이름을 dimen로 지정한 다음 xml에 다음과 같이 선언합니다. 앞에서 설명한 것과 같은 방법으로 해당 values-xlarge을 만들고 해당 파일에 dimen 파일을 추가하십시오.

이것은 화면 크기에 따라 다른 레이아웃을 만들고 크기 당 여러 밀도 픽셀을 얻을 수 있기 때문에 매우 유용한 메커니즘입니다. 이 조건들 중 어느 것도 듣지 못했다면 나에게 더 자세한 내용을 제공 해달라고 부탁하십시오.

편집 : 문서에서

res/layout/my_layout.xml    // layout for normal screen size ("default") 

res/layout-small/my_layout.xml  // layout for small screen size 

res/layout-large/my_layout.xml  // layout for large screen size 

res/layout-xlarge/my_layout.xml  // layout for extra large screen size 

res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation 

당신은 디렉토리 이런 종류의 정확히 하시겠습니까? 도대체 clock.xml과 같은 레이아웃 파일 이름을 사용합니까?

ANOTHER 편집

는 언급합니다 : 그냥 번호를 대체하는 것이 아니라 전체 레이아웃 폴더를로드 전환이 훨씬 더 효율적 당신이 추측 수 있기 때문에 그것은 훨씬 더 효율적입니다

. 그럼에도 불구하고 치수를 재사용하고 레이아웃간에 앞뒤로 이동하지 않고 "그 치수가 다시 무엇인지"를 확인할 수 있습니다. 큰 버튼의 고정 치수와 같습니다.

더욱 중요한 것은 각 폴더를 특정 이유로 확장 할 수 있습니다. 동일한 레이아웃이지만 다른 치수를 원할 경우 전체 레이아웃을 복사하여 붙여 넣지 않는 치수를 재정의해야합니다. 더 의미가 있지, 안 그래?

그리고 노력은 거의 똑같습니다. layout-large/ 폴더와 마찬가지로 values-large/이 표시됩니다. 필자가 제공 한 문서와 인터넷을 통해 좋은 예가 있습니다.

+0

layout-xlarge가 작동하지 않음이 폴더 안의 xml이로드되지 않습니다. 왜? – rxlky

+0

미안하지만 내 실수는 레이아웃이 커야합니다. Btw, 149 dpi로 800x1280이 XLARGE가 아닌 것은 어떻습니까? http://developer.android.com/guide/practices/screens_support.html#testing에 따르면 160dpi의 1280x800 (WXGA)은 XLARGE로 간주됩니다 – rxlky

+0

나중에 사용하고 세부 정보를 포함 할 수 있도록 내 대답을 편집했습니다. 필자는 각 전화기의 사양에 대해서는 알지 못하지만, 필자가 제공 한 문서에는 시장에서 사용할 수있는 모든 화면 너비 및 화면 밀도와 사용자 정의를 위해 추가해야하는 항목에 대한 자세한 내용이 나와 있습니다. 새로운'layout-xxx /'폴더는 새로운 레이아웃을 제공하는 아주 쉬운 방법이지만, 앞서 언급 한'@ dimen' 솔루션을 좀 더 자세하게 확인하십시오. 훨씬 더 효율적이며'... = 45dp'는 없어야합니다. . 그냥 제안 ... :) – 10s