我試圖通過展開視圖層次結構來優化Android應用程序中的佈局。這是一個特別困難的!如何優化此佈局?
這種佈局有一個主的LinearLayout以保持頂部和底部行(這是水平方向的子LinearLayouts本身)。中間的四個項目中的每一個都是垂直的RelativeLayout(以適應ImageView和textView)使用layout_weights分佈。每行包含兩個項目也是一個水平LinearLayout。不用說,這種佈局效率低下,導致很多「編舞者跳過幀」的信息在繪製時出現。我想消除這些嵌套的佈局,但是AFAIK RelativeLayout在平行排列行中的項和垂直排列在中間的兩行中沒有幫助。另外,我考慮用複合drawable替換ImageView和TextView,但我不知道如何控制drawable的大小。
任何幫助表示讚賞!
編輯: 下面是佈局的粗略描述。
<!-- The top bar -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="80dip"
android:background="@drawable/some_image">
...
</LinearLayout>
<!-- Central Layout -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="2"
android:orientation="vertical">
<!-- First Row -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:baselineAligned="false"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:weightSum="2">
<!-- Item 1 -->
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical">
<!-- ImageView and TextView here -->
</RelativeLayout>
<!-- Item 2 -->
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical">
<!-- ImageView and TextView here -->
</RelativeLayout>
</LinearLayout>
<!-- End of first row layout -->
<!-- Second Row -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:baselineAligned="false"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:weightSum="2">
<!-- Item 3 -->
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical">
<!-- ImageView and TextView here -->
</RelativeLayout>
<!-- Item 4 -->
<RelativeLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical">
<!-- ImageView and TextView here -->
</RelativeLayout>
</LinearLayout>
<!-- End of second row layout -->
</LinearLayout>
<!-- End of central layout -->
<!-- Bottom bar -->
<LinearLayout...>
....
</LinearLayout>
發佈你現有的xml文件不是很有幫助,而不是解釋 – Bigflow
相信我,你不想看到它!不過,我想我可以添加一個「僞佈局」。 – WeNeigh