1
我已經瀏覽了一下互聯網瞭解了一下,試圖找到一些關於XML設計的指南。Android正確的佈局設計
到目前爲止,我發現最好的設計是保持佈局「平坦」,這意味着保持佈局嵌套到最小。
基本上我有四個下面的佈局堆疊在一起。我沒有添加超過4個的計劃。每個之間唯一不同的是simple_detail_image中的圖像。我找到的選項是使用<include>
爲每個項目,然後以編程方式更改圖像。
這是最佳實踐還是有更實際的東西?
我探索過的另一個選擇是製作一個ListView
並用它們填充它,但看起來像是過度殺傷。
<?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>
如果整個事情正在重複使用'ListView' – kId 2014-10-06 05:41:16
等等,這4個佈局在哪裏?我看到一個4意見。因此這裏的嵌套是零。 – Rob 2014-10-06 06:14:03
我沒有發佈代表它的圖片的聲望。我上面展示的視圖是我想要堆疊的4個視圖。當我提到嵌套時,我指的是儘可能少地使用'LinearLayouts'或它們的等價物。我的文章的要點是要找到**適當**的方式來安排上述代碼到4行。 – Sherlock 2014-10-06 06:37:39