2013-04-07 5 views
0

모든 유형의 타블렛에 적합한 다음 레이아웃을 만들고 싶습니다. 드로어 블에 배치하고 편집 할 때 다른 설정을 사용할 수 있다는 것을 알고 있습니다 만,이를 달성하기위한 대안이 있습니까? 내 XML 코드 enter image description herealertDialog 레이아웃을 최적화 하시겠습니까?

다음 입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
    > 
<TextView 
    android:id="@+id/widget38" 
    android:layout_width="480dp" 
    android:layout_height="45dp" 
    android:background="@color/White" 
    android:text="Reminder" 
    android:textSize="20dp" 
    android:textColor="@color/Black" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" /> 

<TextView 
    android:id="@+id/label" 
    android:layout_width="476dp" 
    android:layout_height="70dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/widget38" 
    android:background="@color/White" 
    android:text="DID you have your Pill?" 
    android:textColor="@color/Black" 
    android:textSize="40dp" /> 

<Button 
    android:id="@+id/yes" 
    android:layout_width="224dp" 
    android:layout_height="161dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignRight="@+id/widget38" 
    android:layout_below="@+id/label" 
    android:background="@color/Green" 
    android:text="Yes" /> 

<Button 
    android:id="@+id/no" 
    android:layout_width="239dp" 
    android:layout_height="161dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/label" 
    android:layout_toRightOf="@+id/widget38" 
    android:background="@color/Red" 
    android:text="No/Cancel" /> 

</RelativeLayout> 

내 자바 코드 경고를 생성합니다

Button button=(Button)findViewById(R.id.button1); 
     button.setOnClickListener(new View.OnClickListener() { 

      @SuppressWarnings("deprecation") 
      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 


       View view= getLayoutInflater().inflate(R.layout.custom, null); 
       final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 


       builder.setView(view); 
       // set the custom dialog components - text, image and button 
        TextView t=(TextView)view.findViewById(R.id.widget38); 
       TextView text = (TextView)view.findViewById(R.id.label); 

       Button yesButton = (Button) view.findViewById(R.id.yes); 
       Button noButton=(Button)view.findViewById(R.id.no); 



       final AlertDialog dialog=builder.create(); 

       noButton.setOnClickListener(new OnClickListener() { 
        @Override 
        public void onClick(View v) { 
         dialog.dismiss(); 
        } 
       }); 



       yesButton.setOnClickListener(new OnClickListener() { 
        @Override 
        public void onClick(View v) { 
         dialog.dismiss(); 
        } 
       }); 

      Display display = getWindowManager().getDefaultDisplay(); 
       int width = display.getWidth(); 
       int height = display.getHeight(); 

       dialog.show(); 
       dialog.getWindow().setLayout(width, height); 

을 다음은 7 인치 크기의 모든 태블릿을 만들 수 내 의도 답변을 기반으로 코드를 편집하고 Eclipse IDE에서 올바르게 표시하지만 에뮬레이터에서 시도 할 때 매우 다르게 나타납니다. 재생성 할 수 없습니다 .. 도와주세요. output that appears in nexus 7 emulator however it shows correctly in eclipse xml editor

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     > 

     <TextView 
      android:id="@+id/ReminderMessage" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:background="@color/Aqua" 
     android:textColor="@color/Black" 
    android:textSize="10dp" 
      /> 

    </RelativeLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="3" 
     android:baselineAligned="false" 
     android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 

     > 

     <RelativeLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="#0F0" > 

      <Button 
       android:id="@+id/yes" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="Yes" 
      android:background="@color/Green" 
      android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/ReminderMessage" 


       > 
      </Button> 



     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="#F00" > 


      <Button 
       android:id="@+id/no" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="No/Cancel" 
      android:background="@color/Red" 
      android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/ReminderMessage" 
       > 
      </Button> 

     </RelativeLayout> 

    </LinearLayout> 

</LinearLayout> 
+0

내 실수, 내가 렌더링 할 때 선형 레이아웃 역 가중치를 사용하는 것이 잊었 : http://stackoverflow.com/questions/8381021/why-does-the-linearlayout-attribute-layout-weight-seem-to -do-the-opposite-of-w. 그냥 위쪽/아래쪽 부분에 대한 가중치를 전환하고 그것은 inteneded로 작동한다 – munch1324

+0

아 지금 작동 ... 그것은 이클립스에서 다르게 표시하지만 그것은 의도적으로 장치에 의도 된 방법을 보여줍니다 .. 이것은 의도적으로 구글이나 WA에 의해 이루어졌다 실수로 ... .. 다시 한 번 고마워 .... –

+0

나는 정직하지 않을거야. 나는 그것이 몇 번 나를 바보 취급했다는 것을 안다 :-) – munch1324

답변

1

편집 는 : 선형 레이아웃에 대한 역 가중치를 보여주기 위해 수정. 서로 다른 크기 다른 모습을 원하는 경우

는, 레이아웃/레이아웃 대형/레이아웃 초대형 폴더는 서로 다른 크기 범위 (예 : 7 ")에 대해 구체적으로 경고를 정의하는 가장 쉬운 방법이 될 것입니다.

Eclipse를 IDE로 사용하는 경우 "모든 화면"을 선택하여 다양한 장치 개요를 확인하십시오.

특정 비율을 염두에 둔 경우 선형 레이아웃을 사용하면 선형 레이아웃의 경우 다음과 같습니다 (화면 크기에 따라 비율이 유지됩니다) :

enter image description here

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="3" > 

    </RelativeLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" > 

     <RelativeLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="#0F0" > 

     </RelativeLayout> 

     <RelativeLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="#F00" > 

     </RelativeLayout> 

    </LinearLayout> 

</LinearLayout> 
+0

오, 좋아, 거기에 미리보기 화면 옵션이 있었는지 몰랐다 .... 감사합니다! –

+0

수정 된 답변을 기반으로 eclipse IDE에서 제대로 표시되지만 장치에 올바르게 표시되지 않습니다. 세부 정보는 위에서 편집됩니다. –

관련 문제