2016-12-10 3 views
0

Ich versuche, dieses Layout für jede Android-Bildschirmgröße kompatibel zu machen. Ich habe viele Dinge ausprobiert, wie zum Beispiel verschiedene Layout-Ordner, aber es funktioniert nicht. Ich habe diesen Link auch besucht, aber ich verstehe es nicht viel. Linkwie man Layout mit cardviews kompatibel für jede Android-Bildschirmgröße

<?xml version="1.0" encoding="utf-8"?> 
 

 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
 
    android:id="@+id/scr" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    > 
 

 

 
    <LinearLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:orientation="vertical" 
 
     android:id="@+id/parentPanel" 
 
     android:padding="2dp"> 
 

 
     <TextView 
 
      android:padding="5dp" 
 
      android:layout_width="match_parent" 
 
      android:layout_height="35dp" 
 
      android:background="@drawable/nav_banner_background" 
 
      android:text="Vendors Type" 
 
      android:textAlignment="center" 
 
      android:textSize="20dp" 
 
      android:textColor="@color/buttonText" 
 
      /> 
 

 

 
     <LinearLayout 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:orientation="horizontal" 
 
      android:id="@+id/firstPanel"> 
 
      <android.support.v7.widget.CardView 
 
       xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
 
       android:id="@+id/card_view_mehandi" 
 
       android:layout_width="160dp" 
 
       android:layout_height="150dp" 
 
       card_view:cardCornerRadius="6dp" 
 
       android:layout_marginBottom="5dp" 
 
       android:layout_marginTop="5dp" 
 
       android:layout_marginLeft="40dp"> 
 
       <LinearLayout 
 
        android:layout_width="match_parent" 
 
        android:layout_height="fill_parent" 
 
        android:orientation="vertical"> 
 
        <ImageView 
 
         android:onClick="photo" 
 
         android:id="@+id/photographerImageView" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="0dp" 
 
         android:layout_weight="1.0" 
 
         android:scaleType="centerCrop" 
 
         android:background="@drawable/vender_photographer" /> 
 
        <TextView 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:text="Photographer" 
 
         android:layout_marginLeft="50dp" 
 
         android:layout_marginBottom="5dp" 
 
         /> 
 
       </LinearLayout> 
 
      </android.support.v7.widget.CardView> 
 
      <android.support.v7.widget.CardView 
 
       xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
 
       android:id="@+id/card_view_barat" 
 
       android:layout_width="160dp" 
 
       android:layout_height="150dp" 
 
       android:layout_margin="5dp" 
 
       card_view:cardCornerRadius="6dp"> 
 
       <LinearLayout 
 
        android:layout_width="match_parent" 
 
        android:layout_height="fill_parent" 
 
        android:orientation="vertical"> 
 
        <ImageView 
 
         android:onClick="cat" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="0dp" 
 
         android:layout_weight="1.0" 
 
         android:scaleType="centerCrop" 
 
         android:background="@drawable/vender_wedding_caterer"/> 
 
        <TextView 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:text="Caterer" 
 
         android:layout_marginLeft="50dp" 
 
         android:layout_marginBottom="5dp" 
 
         /> 
 
       </LinearLayout> 
 
      </android.support.v7.widget.CardView> 
 

 

 
     </LinearLayout> 
 

 
     <LinearLayout 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:orientation="horizontal" 
 
      android:id="@+id/secondPanel"> 
 
      <android.support.v7.widget.CardView 
 
       xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
 
       android:id="@+id/card_view_walima" 
 
       android:layout_width="160dp" 
 
       android:layout_height="150dp" 
 
       card_view:cardCornerRadius="6dp" 
 
       android:layout_marginBottom="5dp" 
 
       android:layout_marginTop="5dp" 
 
       android:layout_marginLeft="40dp"> 
 
       <LinearLayout 
 
        android:layout_width="match_parent" 
 
        android:layout_height="fill_parent" 
 
        android:orientation="vertical"> 
 
        <ImageView 
 
         android:onClick="org" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="0dp" 
 
         android:layout_weight="1.0" 
 
         android:scaleType="centerCrop" 
 
         android:background="@drawable/vender_wedding_organizer" 
 
         /> 
 
        <TextView 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:text="Organizer" 
 
         android:layout_marginLeft="50dp" 
 
         android:layout_marginBottom="5dp" 
 
         /> 
 
       </LinearLayout> 
 
      </android.support.v7.widget.CardView> 
 
      <android.support.v7.widget.CardView 
 
       xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
 
       android:id="@+id/card_view_nikah" 
 
       android:layout_width="160dp" 
 
       android:layout_height="150dp" 
 
       android:layout_margin="5dp" 
 
       card_view:cardCornerRadius="6dp"> 
 
       <LinearLayout 
 
        android:layout_width="match_parent" 
 
        android:layout_height="fill_parent" 
 
        android:orientation="vertical"> 
 
        <ImageView 
 
         android:onClick="flow" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="0dp" 
 
         android:layout_weight="1.0" 
 
         android:scaleType="centerCrop" 
 
         android:background="@drawable/vender_flower_deco" /> 
 
        <TextView 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:text="Flower Decorer" 
 
         android:layout_marginLeft="50dp" 
 
         android:layout_marginBottom="5dp" 
 
         /> 
 
       </LinearLayout> 
 
      </android.support.v7.widget.CardView> 
 

 

 
     </LinearLayout> 
 

 
     <LinearLayout 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:orientation="horizontal" 
 
      android:id="@+id/thirdPanel"> 
 
      <android.support.v7.widget.CardView 
 
       xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
 
       android:id="@+id/card_view_engagement" 
 
       android:layout_width="160dp" 
 
       android:layout_height="150dp" 
 
       card_view:cardCornerRadius="6dp" 
 
       android:layout_marginBottom="5dp" 
 
       android:layout_marginTop="5dp" 
 
       android:layout_marginLeft="40dp"> 
 
       <LinearLayout 
 
        android:layout_width="match_parent" 
 
        android:layout_height="fill_parent" 
 
        android:orientation="vertical"> 
 
        <ImageView 
 
         android:onClick="dec" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="0dp" 
 
         android:layout_weight="1.0" 
 
         android:scaleType="centerCrop" 
 
         android:background="@drawable/vender_wedding_decorations" /> 
 
        <TextView 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:text="Wedding Decorator" 
 
         android:layout_marginLeft="50dp" 
 
         android:layout_marginBottom="5dp" 
 
         /> 
 
       </LinearLayout> 
 
      </android.support.v7.widget.CardView> 
 
      <android.support.v7.widget.CardView 
 
       xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
 
       android:id="@+id/card_view_aqeeqah" 
 
       android:layout_width="160dp" 
 
       android:layout_height="150dp" 
 
       android:layout_margin="5dp" 
 
       card_view:cardCornerRadius="6dp"> 
 
       <LinearLayout 
 
        android:layout_width="match_parent" 
 
        android:layout_height="fill_parent" 
 
        android:orientation="vertical"> 
 
        <ImageView 
 
         android:onClick="dj" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="0dp" 
 
         android:layout_weight="1.0" 
 
         android:scaleType="centerCrop" 
 
         android:background="@drawable/vender_dj" 
 
         /> 
 
        <TextView 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:text="DJ" 
 
         android:layout_marginLeft="50dp" 
 
         android:layout_marginBottom="5dp" 
 
         /> 
 
       </LinearLayout> 
 
      </android.support.v7.widget.CardView> 
 

 

 

 

 

 

 

 
     </LinearLayout> 
 

 

 
    </LinearLayout> 
 
</ScrollView>

Antwort

0

Ich habe das Problem zu lösen, nur um Gewicht von unterschiedlicher Größe statt Ränder hinzufügen müssen.

<?xml version="1.0" encoding="utf-8"?> 
 

 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
 
    android:id="@+id/scr" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    > 
 

 

 
    <LinearLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:orientation="vertical" 
 
     android:id="@+id/parentPanel" 
 
     android:padding="2dp"> 
 

 
     <TextView 
 
      android:padding="5dp" 
 
      android:layout_width="match_parent" 
 
      android:layout_height="35dp" 
 
      android:background="@drawable/nav_banner_background" 
 
      android:text="Vendors Type" 
 
      android:textAlignment="center" 
 
      android:textSize="20dp" 
 
      android:textColor="@color/buttonText" 
 
      /> 
 

 

 
     <LinearLayout 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:orientation="horizontal" 
 
      android:id="@+id/firstPanel"> 
 
      <android.support.v7.widget.CardView 
 
       xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
 
       android:id="@+id/card_view_mehandi" 
 
       android:layout_width="wrap_content" 
 
       android:layout_height="150dp" 
 
       card_view:cardCornerRadius="6dp" 
 
       android:layout_margin="5dp" 
 
       android:layout_weight="2"> 
 
       <LinearLayout 
 
        android:layout_width="match_parent" 
 
        android:layout_height="fill_parent" 
 
        android:orientation="vertical"> 
 
        <ImageView 
 
         android:onClick="photo" 
 
         android:id="@+id/photographerImageView" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="0dp" 
 
         android:layout_weight="1.0" 
 
         android:scaleType="centerCrop" 
 
         android:background="@drawable/vender_photographer" /> 
 
        <TextView 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:text="Photographer" 
 
         android:textAlignment="center" /> 
 
       </LinearLayout> 
 
      </android.support.v7.widget.CardView> 
 
      <android.support.v7.widget.CardView 
 
       xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
 
       android:id="@+id/card_view_barat" 
 
       android:layout_width="wrap_content" 
 
       android:layout_height="150dp" 
 
       card_view:cardCornerRadius="6dp" 
 
       android:layout_weight="2" 
 
       android:layout_margin="5dp"> 
 
       <LinearLayout 
 
        android:layout_width="match_parent" 
 
        android:layout_height="fill_parent" 
 
        android:orientation="vertical"> 
 
        <ImageView 
 
         android:onClick="cat" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="0dp" 
 
         android:layout_weight="1.0" 
 
         android:scaleType="centerCrop" 
 
         android:background="@drawable/vender_wedding_caterer"/> 
 
        <TextView 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:text="Caterer" 
 
         android:textAlignment="center" /> 
 
       </LinearLayout> 
 
      </android.support.v7.widget.CardView> 
 

 

 
     </LinearLayout> 
 

 
     <LinearLayout 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:orientation="horizontal" 
 
      android:id="@+id/secondPanel"> 
 
      <android.support.v7.widget.CardView 
 
       xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
 
       android:id="@+id/card_view_walima" 
 
       android:layout_width="wrap_content" 
 
       android:layout_height="150dp" 
 
       card_view:cardCornerRadius="6dp" 
 
       android:layout_weight="2 
 
       " 
 
       android:layout_margin="5dp"> 
 
       <LinearLayout 
 
        android:layout_width="match_parent" 
 
        android:layout_height="fill_parent" 
 
        android:orientation="vertical"> 
 
        <ImageView 
 
         android:onClick="org" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="0dp" 
 
         android:layout_weight="1.0" 
 
         android:scaleType="centerCrop" 
 
         android:background="@drawable/vender_wedding_organizer" 
 
         /> 
 
        <TextView 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:text="Organizer" 
 
         android:textAlignment="center" /> 
 
       </LinearLayout> 
 
      </android.support.v7.widget.CardView> 
 
      <android.support.v7.widget.CardView 
 
       xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
 
       android:id="@+id/card_view_nikah" 
 
       android:layout_width="wrap_content" 
 
       android:layout_height="150dp" 
 
       android:layout_weight="2" 
 
       card_view:cardCornerRadius="6dp" 
 
       android:layout_margin="5dp"> 
 
       <LinearLayout 
 
        android:layout_width="match_parent" 
 
        android:layout_height="fill_parent" 
 
        android:orientation="vertical"> 
 
        <ImageView 
 
         android:onClick="flow" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="0dp" 
 
         android:layout_weight="1.0" 
 
         android:scaleType="centerCrop" 
 
         android:background="@drawable/vender_flower_deco" /> 
 
        <TextView 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:text="Flower Decorer" 
 
         android:textAlignment="center" /> 
 
       </LinearLayout> 
 
      </android.support.v7.widget.CardView> 
 

 

 
     </LinearLayout> 
 

 
     <LinearLayout 
 
      android:layout_width="match_parent" 
 
      android:layout_height="wrap_content" 
 
      android:orientation="horizontal" 
 
      android:id="@+id/thirdPanel" 
 
      > 
 
      <android.support.v7.widget.CardView 
 
       xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
 
       android:id="@+id/card_view_engagement" 
 
       android:layout_width="wrap_content" 
 
       android:layout_height="150dp" 
 
       card_view:cardCornerRadius="6dp" 
 
       android:layout_weight="2" 
 
       android:layout_margin="5dp"> 
 
       <LinearLayout 
 
        android:layout_width="match_parent" 
 
        android:layout_height="fill_parent" 
 
        android:orientation="vertical"> 
 
        <ImageView 
 
         android:onClick="dec" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="0dp" 
 
         android:layout_weight="1.0" 
 
         android:scaleType="centerCrop" 
 
         android:background="@drawable/vender_wedding_decorations" /> 
 
        <TextView 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:text="Wedding Decorator" 
 
         android:textAlignment="center" /> 
 
       </LinearLayout> 
 
      </android.support.v7.widget.CardView> 
 
      <android.support.v7.widget.CardView 
 
       xmlns:android="http://schemas.android.com/apk/res/android" 
 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
 
       android:id="@+id/card_view_aqeeqah" 
 
       android:layout_width="wrap_content" 
 
       android:layout_height="150dp" 
 
       android:layout_weight="2" 
 
       card_view:cardCornerRadius="6dp" 
 
       android:layout_margin="5dp"> 
 
       <LinearLayout 
 
        android:layout_width="match_parent" 
 
        android:layout_height="fill_parent" 
 
        android:orientation="vertical"> 
 
        <ImageView 
 
         android:onClick="dj" 
 
         android:layout_width="match_parent" 
 
         android:layout_height="0dp" 
 
         android:layout_weight="1.0" 
 
         android:scaleType="centerCrop" 
 
         android:background="@drawable/vender_dj" 
 
         /> 
 
        <TextView 
 
         android:layout_width="match_parent" 
 
         android:layout_height="wrap_content" 
 
         android:text="DJ" 
 
         android:textAlignment="center" /> 
 
       </LinearLayout> 
 
      </android.support.v7.widget.CardView> 
 

 

 

 

 

 

 

 
     </LinearLayout> 
 

 

 
    </LinearLayout> 
 
</ScrollView>

0
compile 'com.intuit.sdp:sdp-android:1.0.3' 

Kompilieren diese Abhängigkeit in Ihrer gradle Datei und SDP anstelle von dp wie

android:width="@dimen/_40sdp" 

und es wird für alle Geräte funktionieren.

Verwandte Themen