2012-02-27 5 views
1

Я разработчик новичка, я создал макет, который соответствует моим ожиданиям, но я боюсь, что его конструкция слишком сложна.Как я могу упростить свой макет?

Я использовал много макетов, но я не вижу, как построить аналогичную компоновку без смешивания линейных и относительных макетов, возможно ли это?

Как я могу упростить этот макет? Спасибо за ваши идеи.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="#ffffff" > 

<LinearLayout 
    android:id="@+id/header" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/black_blue_gradient" 
    android:paddingBottom="5dip" 
    android:paddingTop="24dip" > 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/header" > 

    <LinearLayout 
     android:id="@+id/linearlayout01left" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="40" 
     android:orientation="horizontal" > 

     <RelativeLayout 
      android:id="@+id/relativeLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <LinearLayout 
       android:id="@+id/footer" 
       android:layout_width="fill_parent" 
       android:layout_height="8dp" 
       android:layout_alignParentBottom="true" 
       android:background="@drawable/b_bgradient" > 
      </LinearLayout> 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_above="@+id/footer" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentTop="true" 
       android:src="@drawable/oranwall_ovosh" /> 
     </RelativeLayout> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearlayout02right" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="60" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:background="#E9EEF2" 
      android:gravity="center_vertical|center_horizontal" 
      android:text="@string/My_txt" 
      android:textColor="#535A5F" 
      android:textSize="14sp" /> 
    </LinearLayout> 
</LinearLayout> 

</RelativeLayout> 
+0

Нет ничего плохого в использовании нескольких макетов для достижения желаемых результатов. В окончательных скомпилированных приложениях XML хранятся в двоичной форме, и загрузка выполняется очень быстро. У вас есть пара пустых LinearLayouts (верхний и нижний колонтитул) - какова их цель? Вы можете удалить их? –

ответ

2

Попробуйте. Не забывайте размещать свой архив и прочие ресурсы.

 <?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TableRow 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/ic_launcher"> 
    </TableRow> 

    <TableRow 
     android:id="@+id/body" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="3"> 

     <LinearLayout 
      android:id="@+id/linearLayout1" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" > 

      <LinearLayout 
       android:id="@+id/linearLayout2" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" > 

       <ImageView 
        android:id="@+id/imageView1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_weight="1" 
        android:src="@drawable/perm" /> 

       <TableRow 
        android:id="@+id/footer" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="0.5" 
        android:background="@drawable/ic_launcher" > 
       </TableRow> 

      </LinearLayout> 

     </LinearLayout> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:gravity="center" 
      android:text="Medium Text" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

    </TableRow> 

</LinearLayout> 
+0

Зачем использовать TableRows? – Knossos

+0

Почему бы и нет? Мне было удобно контролировать внешний вид макета во многих случаях –

+0

Отличная идея, но мой нижний колонтитул может быть только под левой частью –

1

Есть несколько изменений, я хотел бы сделать:

<?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="match_parent" 
    android:background="#ffffff" 
    android:orientation="vertical" > 

    <!-- I don't understand the point of this one: --> 
    <LinearLayout 
     android:id="@+id/header" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/black_blue_gradient" 
     android:paddingBottom="5dip" 
     android:paddingTop="24dip" > 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1" > 

     <LinearLayout 
      android:id="@+id/linearlayout01left" 
      android:layout_width="0dip" 
      android:layout_height="match_parent" 
      android:layout_weight="0.4" 
      android:orientation="horizontal" > 

      <RelativeLayout 
       android:id="@+id/relativeLayout1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 

       <!-- I don't understand the point of this one --> 
       <LinearLayout 
        android:id="@+id/footer" 
        android:layout_width="match_parent" 
        android:layout_height="8dp" 
        android:layout_alignParentBottom="true" 
        android:background="@drawable/b_bgradient" > 
       </LinearLayout> 

       <ImageView 
        android:id="@+id/imageView1" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_above="@+id/footer" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:src="@drawable/oranwall_ovosh" /> 
      </RelativeLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/linearlayout02right" 
      android:layout_width="0dip" 
      android:layout_height="match_parent" 
      android:layout_weight="0.6" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:background="#E9EEF2" 
       android:gravity="center_vertical|center_horizontal" 
       android:text="@string/My_txt" 
       android:textColor="#535A5F" 
       android:textSize="14sp" /> 
     </LinearLayout> 
    </LinearLayout> 

</LinearLayout> 
+0

На данный момент они содержат только ухудшенные (я использую цветовой код, чтобы помочь пользователю найти в приложении) Я согласен, их можно легко заменить TextView с фоном –

Смежные вопросы