android - Responsive activity -
i'm learning develop android application 2 months now. have lot of question according layouts on android.
i read this article , others on official documentation website (can't find link). understand in order screen size of elements matches resolution of phone, need use density-independent pixel (dp)
element.
let's imagine order layout according documentation :
res/layout/main_activity.xml # handsets (smaller 600dp available width) res/layout-sw600dp/main_activity.xml # 7” tablets (600dp wide , bigger) res/layout-sw720dp/main_activity.xml # 10” tablets (720dp wide , bigger)
just talk handset configuration. read in documentation the density-independent pixel equivalent 1 physical pixel on 160 dpi screen, baseline density assumed system "medium" density screen
. maximum height , width can use in res/layout/main_activity.xml
in dp ? if have same layout 4, 5, 6" phones, how possible me set image @ 50% of screen length using dp example ?
i must forget me understand how works..
you can use percentrelativelayout
percent support library
, see example :
<android.support.percent.percentrelativelayout 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"> <view android:id="@+id/top_left" android:layout_width="0dp" android:layout_height="0dp" android:layout_alignparenttop="true" android:background="#ff44aacc" app:layout_heightpercent="20%" app:layout_widthpercent="70%" /> <view android:id="@+id/top_right" android:layout_width="0dp" android:layout_height="0dp" android:layout_alignparenttop="true" android:layout_torightof="@+id/top_left" android:background="#ffe40000" app:layout_heightpercent="20%" app:layout_widthpercent="30%" /> <view android:id="@+id/bottom" android:layout_width="match_parent" android:layout_height="0dp" android:layout_below="@+id/top_left" android:background="#ff00ff22" app:layout_heightpercent="80%" /> </android.support.percent.percentrelativelayout>
the result :
don't froget add compile 'com.android.support:percent:23.3.0'
in build.gradle
check tutorial more informations how constructing view layouts.
Comments
Post a Comment