![](/img/trans.png)
[英]How to fix screen size compatible to all android device in android?
[英]How to make a layout, with cardviews compatible for every android screen size device?
我試圖使此布局與每個Android屏幕尺寸兼容。 我已經嘗試了很多方法,例如制作不同的布局文件夾,但無法正常工作。 我也遵循此鏈接,但是我不太了解。 鏈接
<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>
我已經解決了這個問題,只是需要增加重量而不是來自其他尺寸的邊距。
<?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>
compile 'com.intuit.sdp:sdp-android:1.0.3'
將此依賴關系編譯到gradle文件中,並使用sdp代替dp,例如
android:width="@dimen/_40sdp"
它將適用於所有設備。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.