Android Proper Layout Design -
i've looked around net bit trying find guides on xml design.
so far i've found best design maintain layout "flat", meaning keeping layout nesting minimum.
basically have 4 of layout below stacked on top of each other. have no plans of adding more 4. thing differs between each image in simple_detail_image. options i've found using <include>
each item , programmatically changing images.
is best practice or there more practical?
another alternative i've explored making listview
, populating these seemed overkill.
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/shape_rounded" android:padding="4dp" android:orientation="horizontal"> <imageview android:id="@+id/simple_detail_image" android:layout_width="72dp" android:layout_height="72dp" android:src="@drawable/ic_launcher"/> <textview android:id="@+id/simple_detail_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginleft="12dp" android:layout_marginstart="12dp" android:text="hi"/> <space android:layout_weight="1" android:layout_width="0dp" android:layout_height="wrap_content"/> <imageview android:layout_gravity="center" android:layout_width="32dp" android:layout_height="32dp" android:layout_marginright="@dimen/chevron_horizontal_margin" android:layout_marginend="@dimen/chevron_horizontal_margin" android:src="@drawable/ic_chevron_gray"/> </linearlayout>
you simplify whole thing using single textview in place of whole layout, no images , no container.
since textview can contain different compound drawables @ same time. instance:
android:drawablepadding="4dp" android:drawableleft="@drawable/ic_launcher" android:drawableright="@drawable/ic_chevron_gray"
you can include 4 textviews in outer (vertical) container , done.
then, in code, alter drawableleft:
//public void setcompounddrawableswithintrinsicbounds (int left, int top, int right, int bottom) public void setcompounddrawableswithintrinsicbounds (r.drawable.your_left_drawable_1, 0, r.drawable.ic_chevron_gray, 0);
this maintain layout super flat , efficient.
android android-layout
No comments:
Post a Comment