2016-03-28 23 views
1

Android'de bir Grid Düzeni oluşturmak için v7 destek kitaplığından Grid Düzeni kullanıyorum. Layout, Android stüdyosunda ekranları önizlemeden teyit ettiğim daha büyük ekranlı cihazlarda (ekran boyutları> 4 ") mükemmel bir görüntü oluşturur.Fakat, sadece ilk satır olmak üzere daha küçük ekran cihazlarında (gerçek bir cihazda da kontrol edilir) kötü bir şekilde bozulur. . görünür uç ekran kadar ekran aşağıdaki gibidir: (bu durumda Galaxy S) küçük bir ekran cihazı, bir daha büyük bir ekran cihazının üzerindeandroid.support.v7.widget.GridLayout küçük ekranlı cihazlarda bozuldu android

On a larger screen device

üzerinde

On a smaller screen device

(5,1" bu durumda)

Bu konuda

<android.support.v7.widget.GridLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#BDBDBD" 
    android:padding="3dp" 
    app:columnCount="3" 
    app:rowCount="2" 
    android:layout_below="@+id/pager" 
    android:layout_marginLeft="0dp" 
    > 

    <LinearLayout 
     app:layout_column="0" 
     app:layout_columnWeight="1" 
     app:layout_rowWeight="1" 
     android:layout_marginLeft="0dp" 
     android:background="#FFF" 
     android:layout_marginRight="2dp" 
     android:layout_marginBottom="2dp" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:onClick="buttonActions" 
     android:id="@+id/menu1" 
     android:clickable="true" 
     app:layout_row="0" 
     > 
     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu11" 
      android:background="#FFF" 
      android:layout_gravity="center" 
      android:id="@+id/menu1_img" 
      android:onClick="buttonActions" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/menu1" 
      android:gravity="center" 
      android:layout_gravity="center" 
      android:layout_marginTop="3dp" 
      android:id="@+id/menu1_txt" 
      android:onClick="buttonActions" 
      /> 
    </LinearLayout> 
    <LinearLayout 
     app:layout_column="1" 
     app:layout_columnWeight="1" 
     app:layout_rowWeight="1" 
     android:layout_marginLeft="0dp" 
     android:background="#FFF" 
     android:layout_marginRight="2dp" 
     android:layout_marginBottom="2dp" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:id="@+id/menu2" 
     android:onClick="buttonActions" 
     app:layout_row="0" 
     > 
     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu12" 
      android:background="#FFF" 
      android:layout_gravity="center" 
      android:id="@+id/menu2_img" 
      android:onClick="buttonActions" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/menu2" 
      android:gravity="center" 
      android:layout_gravity="center" 
      android:layout_marginTop="3dp" 
      android:id="@+id/menu2_txt" 
      android:onClick="buttonActions" 
      /> 
    </LinearLayout> 
    <LinearLayout 
     app:layout_column="2" 
     app:layout_columnWeight="1" 
     app:layout_rowWeight="1" 
     android:layout_marginLeft="0dp" 
     android:background="#FFF" 
     android:layout_marginRight="2dp" 
     android:layout_marginBottom="2dp" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:onClick="buttonActions" 
     android:id="@+id/menu3" 
     app:layout_row="0" 
     > 
     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu13" 
      android:background="#FFF" 
      android:layout_gravity="center" 
      android:onClick="buttonActions" 
      android:id="@+id/menu3_img" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/menu3" 
      android:gravity="center" 
      android:layout_gravity="center" 
      android:layout_marginTop="3dp" 
      android:onClick="buttonActions" 
      android:id="@+id/menu3_txt" 
      /> 
    </LinearLayout> 
    <LinearLayout 
     app:layout_column="0" 
     app:layout_columnWeight="1" 
     app:layout_rowWeight="1" 
     android:layout_marginLeft="0dp" 
     android:background="#FFF" 
     android:layout_marginRight="2dp" 
     android:layout_marginBottom="2dp" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:id="@+id/menu4" 
     android:onClick="buttonActions" 
     > 
     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu14" 
      android:background="#FFF" 
      android:layout_gravity="center" 
      android:id="@+id/menu4_img" 
      android:onClick="buttonActions" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/menu4" 
      android:gravity="center" 
      android:layout_gravity="center" 
      android:layout_marginTop="3dp" 
      android:id="@+id/menu4_txt" 
      android:onClick="buttonActions" 
      /> 
    </LinearLayout> 
    <LinearLayout 
     app:layout_column="1" 
     app:layout_columnWeight="1" 
     app:layout_rowWeight="1" 
     android:layout_marginLeft="0dp" 
     android:background="#FFF" 
     android:layout_marginRight="2dp" 
     android:layout_marginBottom="2dp" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:id="@+id/menu5" 
     android:onClick="buttonActions" 
     > 
     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu15" 
      android:background="#FFF" 
      android:layout_gravity="center" 
      android:id="@+id/menu5_img" 
      android:onClick="buttonActions" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/menu5" 
      android:gravity="center" 
      android:layout_gravity="center" 
      android:layout_marginTop="3dp" 
      android:id="@+id/menu5_txt" 
      android:onClick="buttonActions" 
      /> 
    </LinearLayout> 
    <LinearLayout 
     app:layout_column="2" 
     app:layout_columnWeight="1" 
     app:layout_rowWeight="1" 
     android:layout_marginLeft="0dp" 
     android:background="#FFF" 
     android:layout_marginRight="2dp" 
     android:layout_marginBottom="2dp" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:onClick="buttonActions" 
     android:id="@+id/menu6" 
     > 
     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu16" 
      android:background="#FFF" 
      android:layout_gravity="center" 
      android:onClick="buttonActions" 
      android:id="@+id/menu6_img" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/menu6" 
      android:gravity="center" 
      android:layout_gravity="center" 
      android:layout_marginTop="3dp" 
      android:onClick="buttonActions" 
      android:id="@+id/menu6_txt" 
      /> 
    </LinearLayout> 
    <LinearLayout 
     app:layout_column="0" 
     app:layout_columnWeight="1" 
     app:layout_rowWeight="1" 
     android:layout_marginLeft="0dp" 
     android:background="#FFF" 
     android:layout_marginRight="2dp" 
     android:layout_marginBottom="2dp" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:id="@+id/menu7" 
     android:onClick="buttonActions" 
     > 
     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu17" 
      android:background="#FFF" 
      android:layout_gravity="center" 
      android:id="@+id/menu7_img" 
      android:onClick="buttonActions" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/menu7" 
      android:gravity="center" 
      android:layout_gravity="center" 
      android:layout_marginTop="3dp" 
      android:onClick="buttonActions" 
      android:id="@+id/menu7_txt" 
      /> 
    </LinearLayout> 
    <LinearLayout 
     app:layout_column="1" 
     app:layout_columnWeight="1" 
     app:layout_rowWeight="1" 
     android:layout_marginLeft="0dp" 
     android:background="#FFF" 
     android:layout_marginRight="2dp" 
     android:layout_marginBottom="2dp" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:onClick="buttonActions" 
     android:id="@+id/menu8" 
     > 
     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu18" 
      android:background="#FFF" 
      android:layout_gravity="center" 
      android:onClick="buttonActions" 
      android:id="@+id/menu8_img" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/menu8" 
      android:gravity="center" 
      android:layout_gravity="center" 
      android:layout_marginTop="3dp" 
      android:onClick="buttonActions" 
      android:id="@+id/menu8_txt" 
      /> 
    </LinearLayout> 
    <LinearLayout 
     app:layout_column="2" 
     app:layout_columnWeight="1" 
     app:layout_rowWeight="1" 
     android:layout_marginLeft="0dp" 
     android:background="#FFF" 
     android:layout_marginRight="2dp" 
     android:layout_marginBottom="2dp" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:onClick="buttonActions" 
     android:id="@+id/menu9" 
     > 
     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/menu19" 
      android:background="#FFF" 
      android:layout_gravity="center" 
      android:onClick="buttonActions" 
      android:id="@+id/menu9_img" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/menu9" 
      android:gravity="center" 
      android:layout_gravity="center" 
      android:layout_marginTop="3dp" 
      android:onClick="buttonActions" 
      android:id="@+id/menu9_txt" 
      /> 
    </LinearLayout> 

</android.support.v7.widget.GridLayout> 

Yardım, küçük cihazlarda uyumluluk sorunu çözmek için mutluluk duyacağız:

Aşağıda aynı kodudur. Şimdiden teşekkürler.

+0

Bu [GridLayout üzerinde blog yazısı] (http://android-developers.blogspot.com/2011/11/new bulabilir ağırlıklarla LinearLayouts kullanarak yaklaşımdır -layout-widgets-space-and-gridlayout.html) yardımcı olur. Veya GridLayout'u ortadan kaldırmanız ve [LinearLayout with heavy] (http://developer.android.com/guide/topics/ui/layout/linear.html#Weight) kullanmanız daha kolay olabilir. – tachyonflux

+0

LinearLayout ile tüm çalışma düzenini, her cihazda ağırlıklar ve çalışmalarla elde ettik. Teşekkürler. –

cevap

0

Bu

<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" android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context="com.ttl.thetravellerslounge.TopNavigation"> 
<include 
    layout="@layout/toolbar" 
    android:id="@+id/toolbar"></include> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:text="TTL Immigration" 
    android:id="@+id/textView" 
    android:textColor="#fff" 
    android:padding="7dp" 
    android:layout_centerHorizontal="true" 
    android:textSize="35sp" 
    /> 
<android.support.v4.view.ViewPager 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="170dp" 
    android:layout_below="@+id/toolbar" 
    > 
</android.support.v4.view.ViewPager> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:layout_below="@+id/pager" 
    android:layout_marginTop="2dp" 
    > 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     > 
     <LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_marginLeft="0dp" 
      android:background="#FFF" 
      android:layout_marginRight="2dp" 
      android:layout_marginBottom="2dp" 
      android:orientation="vertical" 
      android:gravity="center" 
      android:onClick="buttonActions" 
      android:id="@+id/menu1" 
      android:clickable="true" 

      > 
      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/menu11" 
       android:background="#FFF" 
       android:layout_gravity="center" 
       android:id="@+id/menu1_img" 
       android:onClick="buttonActions" 
       /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/menu1" 
       android:gravity="center" 
       android:layout_gravity="center" 
       android:layout_marginTop="3dp" 
       android:id="@+id/menu1_txt" 
       android:onClick="buttonActions" 
       /> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_marginLeft="0dp" 
      android:background="#FFF" 
      android:layout_marginRight="2dp" 
      android:layout_marginBottom="2dp" 
      android:orientation="vertical" 
      android:gravity="center" 
      android:id="@+id/menu2" 
      android:onClick="buttonActions" 

      > 
      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/menu12" 
       android:background="#FFF" 
       android:layout_gravity="center" 
       android:id="@+id/menu2_img" 
       android:onClick="buttonActions" 
       /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/menu2" 
       android:gravity="center" 
       android:layout_gravity="center" 
       android:layout_marginTop="3dp" 
       android:id="@+id/menu2_txt" 
       android:onClick="buttonActions" 
       /> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_marginLeft="0dp" 
      android:background="#FFF" 
      android:layout_marginRight="2dp" 
      android:layout_marginBottom="2dp" 
      android:orientation="vertical" 
      android:gravity="center" 
      android:onClick="buttonActions" 
      android:id="@+id/menu3" 

      > 
      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/menu13" 
       android:background="#FFF" 
       android:layout_gravity="center" 
       android:onClick="buttonActions" 
       android:id="@+id/menu3_img" 
       /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/menu3" 
       android:gravity="center" 
       android:layout_gravity="center" 
       android:layout_marginTop="3dp" 
       android:onClick="buttonActions" 
       android:id="@+id/menu3_txt" 
       /> 
     </LinearLayout> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     > 
     <LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_marginLeft="0dp" 
      android:background="#FFF" 
      android:layout_marginRight="2dp" 
      android:layout_marginBottom="2dp" 
      android:orientation="vertical" 
      android:gravity="center" 
      android:id="@+id/menu4" 
      android:onClick="buttonActions" 
      android:paddingLeft="1dp" 
      > 
      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/menu14" 
       android:background="#FFF" 
       android:layout_gravity="center" 
       android:id="@+id/menu4_img" 
       android:onClick="buttonActions" 
       /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/menu4" 
       android:gravity="center" 
       android:layout_gravity="center" 
       android:layout_marginTop="3dp" 
       android:id="@+id/menu4_txt" 
       android:onClick="buttonActions" 
       /> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_marginLeft="0dp" 
      android:background="#FFF" 
      android:layout_marginRight="2dp" 
      android:layout_marginBottom="2dp" 
      android:orientation="vertical" 
      android:gravity="center" 
      android:id="@+id/menu5" 
      android:onClick="buttonActions" 
      > 
      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/menu15" 
       android:background="#FFF" 
       android:layout_gravity="center" 
       android:id="@+id/menu5_img" 
       android:onClick="buttonActions" 
       /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/menu5" 
       android:gravity="center" 
       android:layout_gravity="center" 
       android:layout_marginTop="3dp" 
       android:id="@+id/menu5_txt" 
       android:onClick="buttonActions" 
       /> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_marginLeft="0dp" 
      android:background="#FFF" 
      android:layout_marginRight="2dp" 
      android:layout_marginBottom="2dp" 
      android:orientation="vertical" 
      android:gravity="center" 
      android:onClick="buttonActions" 
      android:id="@+id/menu6" 
      > 
      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/menu16" 
       android:background="#FFF" 
       android:layout_gravity="center" 
       android:onClick="buttonActions" 
       android:id="@+id/menu6_img" 
       /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/menu6" 
       android:gravity="center" 
       android:layout_gravity="center" 
       android:layout_marginTop="3dp" 
       android:onClick="buttonActions" 
       android:id="@+id/menu6_txt" 
       /> 
     </LinearLayout> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     > 
     <LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_marginLeft="0dp" 
      android:background="#FFF" 
      android:layout_marginRight="2dp" 
      android:layout_marginBottom="2dp" 
      android:orientation="vertical" 
      android:gravity="center" 
      android:id="@+id/menu7" 
      android:onClick="buttonActions" 
      > 
      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/menu17" 
       android:background="#FFF" 
       android:layout_gravity="center" 
       android:id="@+id/menu7_img" 
       android:onClick="buttonActions" 
       /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/menu7" 
       android:gravity="center" 
       android:layout_gravity="center" 
       android:layout_marginTop="3dp" 
       android:onClick="buttonActions" 
       android:id="@+id/menu7_txt" 
       /> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_marginLeft="0dp" 
      android:background="#FFF" 
      android:layout_marginRight="2dp" 
      android:layout_marginBottom="2dp" 
      android:orientation="vertical" 
      android:gravity="center" 
      android:onClick="buttonActions" 
      android:id="@+id/menu8" 
      > 
      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/menu18" 
       android:background="#FFF" 
       android:layout_gravity="center" 
       android:onClick="buttonActions" 
       android:id="@+id/menu8_img" 
       /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/menu8" 
       android:gravity="center" 
       android:layout_gravity="center" 
       android:layout_marginTop="3dp" 
       android:onClick="buttonActions" 
       android:id="@+id/menu8_txt" 
       /> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_marginLeft="0dp" 
      android:background="#FFF" 
      android:layout_marginRight="2dp" 
      android:layout_marginBottom="2dp" 
      android:orientation="vertical" 
      android:gravity="center" 
      android:onClick="socialDialog" 
      android:id="@+id/menu9" 
      > 
      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/menu19" 
       android:background="#FFF" 
       android:layout_gravity="center" 
       android:onClick="socialDialog" 
       android:id="@+id/menu9_img" 
       /> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/menu9" 
       android:gravity="center" 
       android:layout_gravity="center" 
       android:layout_marginTop="3dp" 
       android:onClick="socialDialog" 
       android:id="@+id/menu9_txt" 
       /> 
     </LinearLayout> 


    </LinearLayout> 
</LinearLayout>