0

레이아웃 문제를 해결하려고합니다.이 res/layout/my.xml을 Moto G에서 테스트했는데 괜찮 았지만 Nexus S에서 테스트했을 때 버튼이 너무 컸다. 나는 res/layout-xhdpi/my.xml (Moto G는 xhdpi이고 Nexus는 단지 hdpi이기 때문에)을 시도했지만 레이아웃 중 하나는 항상 두 가지 모두에서 팽창합니다 (각 xhdpi에 대해 전혀 다른 점은 없습니다). 가에 가면 즉시) 볼 수있는 다음 값에Nexus S와 Moto G - 레이아웃을 구분할 수 없음

<LinearLayout 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:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFFFFF" 
    android:orientation="vertical" 
    tools:context=".MainActivity" > 

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

     <ImageView 
      android:id="@+id/imageView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:cropToPadding="true" 
      android:src="@drawable/pil2" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/button1" 
      android:layout_below="@+id/button1" 
      android:height="90dp" 
      android:minWidth="150dp" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/button2" 
      android:layout_below="@+id/button2" 
      android:height="80dp" 
      android:minWidth="150dp" /> 

     <Button 
      android:id="@+id/button4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignLeft="@+id/button1" 
      android:layout_alignParentTop="true" 
      android:height="130dp" 
      android:minWidth="150dp" /> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/button4" 
      android:layout_centerHorizontal="true" 
      android:height="90dp" 
      android:minWidth="150dp" /> 

    </RelativeLayout> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     ads:adUnitId="xxxx" 
     ads:adSize="BANNER" /> 

</LinearLayout> 
+0

드로어 블 리소스 이외의 다른 리소스 리소스에 밀도 리소스 세트 한정자 (예 :'-hdpi')를 사용하면 심각한 코드의 냄새가납니다. 원하는 코드를 얻지 못할 것이라는 것을 거의 확신 할 수 있습니다. 그 외에도 계층 구조보기를 사용하여 레이아웃 규칙에서 어려움을 초래하는 요소를 판별하십시오. – CommonsWare

+0

다음은 Nexus S에서 보이는 모습입니다. http://oi58.tinypic.com/oko8l1.jpg Nexus 5의 모습입니다. http://oi59.tinypic.com/1zlgjud.jpg 물론 버튼은 다음과 같습니다. 제대로 작동하면 투명하게됩니다. 상단의 첫 번째 버튼에는 아무런 기능이 없습니다. marginingTop 대신 자리 표시 자만 있습니다. 나는 항상 내 UI를 재고하고 있지만, 제대로 작동 할 것입니다 어떤 장치에 이렇게 단단한 얻을 수 없습니다. –

+0

PNG/JPEG/배경에 클릭 할 수있는 "버튼"을 표시하려고하는 것 같습니다. 단추가 전체적인 배경과 아무 관련이 없기 때문에 접근 방식은 신뢰할 수 없습니다. – CommonsWare

답변

1

이 dimen.xml 파일이 폴더, 그리고 그렇게하지 .If 3 개 값 폴더 (값, 값-V11, 값-V14)가 이 폴더에 dimens.xml 파일이 있으면 dimens.xml 파일을 만들 수 있으므로 버튼 폭과 높이를 다른 장치마다 다르게 지정할 수 있습니다. 이와 같이 : - 예 : - 값 폴더의 경우. 주요 XML

android:layout_width="@+dimen\button_width" 
android:layout_height="@+dimen\button_height" 

에서

<dimen name="button_width">36dp</dimen> 
<dimen name="button_height">66dp</dimen> 

이제 값-V14에 대한 값-V11

<dimen name="button_width">26dp</dimen> 
<dimen name="button_height">26dp</dimen> 

를 들어

<dimen name="button_width">16dp</dimen> 
<dimen name="button_height">16dp</dimen> 

나는 당신의 문제가 해결되기를 바랍니다.

+0

이 두 장치의 문제를 해결할 수 있다고 생각하지만 다른 장치에서 제대로 작동하는지 어떻게 알 수 있습니까? API 버전 관련 문제가 더 많습니까? 아니면 장치 지향입니까? –

+0

아니요, hdpi 장치, 7 인치 태블릿 및 10 인치 태블릿과 같은 모든 유형의 장치에 대한 문제를 해결할 것입니다. –

관련 문제