2012-03-04 106 views
0

對於我的應用程序,我製作一個屏幕,您可以在其中查看有關商店的信息。這就是我現在得到的(在下面的圖片中)剩餘的區域,我想填寫一個圖像或谷歌地圖視圖。是否有可能通過xml填充剩餘區域?或者我該如何解決這個問題?Android佈局對齊並填充視圖中的剩餘空間

第二個問題是: 正如你可以在白色區域看到的圖標或很好的居中。我想將它上面的塊上的圖標與白色框中圖標的左側對齊。我該怎麼做呢?

代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    >  

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:background="@drawable/winkels_uren_bg" 
    android:paddingTop="25dp" 
    android:paddingBottom="25dp" 
    android:paddingLeft="35dp"> 
    <TextView 
     android:id="@+id/lblStraat" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableLeft="@drawable/map" 
     android:gravity="center_vertical" 
     android:paddingBottom="15dp" 

     /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/telefoonnr" 
     android:drawableLeft="@drawable/telefoon_icon" 
     android:gravity="center_vertical" 
     /> 
</LinearLayout> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:background="#FFFFFF" 
    android:gravity="center_horizontal"> 

    <LinearLayout 
     style="@style/winkelinfoicons"> 
     <ImageButton 
      style="@style/winkelinfoicon" 
      android:id="@+id/icobancontact" 
      android:background="@null" 
      /> 

     <ImageButton 
      style="@style/winkelinfoicon" 
      android:id="@+id/icomarkt" 
      android:background="@null" 
      /> 

    </LinearLayout> 

    <LinearLayout 
     style="@style/winkelinfoicons"> 
     <ImageButton 
      style="@style/winkelinfoicon" 
      android:id="@+id/icoeducatie" 
      android:background="@null" 
      /> 
     <ImageButton 
      style="@style/winkelinfoicon" 
      android:id="@+id/icomobielestand" 
      android:background="@null" 
      /> 
    </LinearLayout> 

    <LinearLayout 
     style="@style/winkelinfoicons"> 
     <ImageButton 
      style="@style/winkelinfoicon" 
      android:id="@+id/icogeschenken" 
      android:background="@null" 
      /> 
     <ImageButton 
      style="@style/winkelinfoicon" 
      android:id="@+id/icovoeding" 
      android:background="@null" 
      /> 
    </LinearLayout> 

    <LinearLayout 
     style="@style/winkelinfoicons"> 
     <ImageButton 
      style="@style/winkelinfoicon" 
      android:id="@+id/icoklasbezoek" 
      android:background="@null" 
      /> 
     <ImageButton 
      style="@style/winkelinfoicon" 
      android:id="@+id/icowinkel" 
      android:background="@null" 
      /> 
    </LinearLayout> 

</LinearLayout> 
</LinearLayout> 

其實我的工作與包括但現在我在這裏粘貼完整的XML :)。

Design image

+0

使用相對佈局。 – Akram 2012-03-04 16:52:13

+0

我想要定位多個屏幕大小。而且我總是擔心在不同的屏幕上它不會一樣。或者不會有問題? – 2012-03-04 16:55:00

+0

只有硬編碼佈局文件時纔會出現問題。 – Akram 2012-03-04 16:58:41

回答

0

如果你有類似的問題,以對齊問題。這是我如何修復它。我計算了圖標的dp寬度。我集中它。我將上面的textviews的寬度設置爲與計算值相同的寬度並居中。

0

LinearLayout支持爲每個孩子分配一個重量,這將有助於佔據空間。此屬性爲視圖指定了「重要性」值,並允許其展開以填充父視圖中的任何剩餘空間。默認權重爲0

計算分配

子之間的任何剩餘空間空間分配給子=(子個體重量)/(線性佈局重量每個兒童的總和)

示例:如果存在是三個文本框,其中兩個聲明權重爲1,而第三個權重不爲0,則剩餘空間分配爲 第1個文本框= 1 /(1 + 1 + 0)第2個文本框= 1 /(1 + 1 + 0)第3個文本框= 0 /(1 + 1 + 0)

試試這個xml,我用重量佔據了剩餘的空間

<?xml version="1.0" encoding="UTF-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="1dip" android:orientation="horizontal"> 
     <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight=".7" android:orientation="vertical"> 
     <Button android:id="@+id/header" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/header" android:text="header" /> 
     <TextView android:id="@+id/editText1" android:layout_width="match_parent" android:layout_weight="4" android:layout_height="275dp" android:text="this is the memo/reciept part \r\n this is the memo/reciept part " /> 
     <EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:layout_span="3" android:padding="18dip" android:text="edit text" android:textColor="#000" android:textSize="18sp" /> 
     <Button android:id="@+id/footer" android:background="@drawable/cashierinputtext" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:textSize="18sp" android:text="footer" android:padding="18dip" android:textColor="#000" /> 
     </LinearLayout> 
     <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="0.5dip" android:layout_weight="1.9" android:gravity="center_vertical|fill_vertical" android:orientation="vertical"> 
     <Button android:id="@+id/F1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="4dip" android:layout_centerHorizontal="true" android:background="@drawable/entrykeybutton" android:layout_weight="1" android:text="f1" /> 
     <Button android:id="@+id/F2" android:layout_width="wrap_content" android:layout_margin="4dip" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:background="@drawable/entrykeybutton" android:layout_weight="1" android:text="f2" /> 
     <Button android:id="@+id/F3" android:layout_width="wrap_content" android:layout_margin="4dip" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_weight="1" android:background="@drawable/entrykeybutton" android:text="f3" /> 
     <Button android:id="@+id/F4" android:layout_width="wrap_content" android:layout_margin="4dip" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:background="@drawable/entrykeybutton" android:layout_weight="1" android:text="f4" /> 
     <Button android:id="@+id/F5" android:layout_width="wrap_content" android:layout_margin="4dip" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_weight="1" android:background="@drawable/entrykeybutton" android:text="f5" /> 
     <Button android:id="@+id/F6" android:layout_width="wrap_content" android:layout_margin="4dip" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:background="@drawable/entrykeybutton" android:text="f6" /> 
     <Button android:id="@+id/F7" android:layout_width="wrap_content" android:layout_margin="4dip" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:background="@drawable/entrykeybutton" android:text="f7" /> 
     <Button android:id="@+id/F8" android:layout_width="wrap_content" android:layout_margin="4dip" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:background="@drawable/entrykeybutton" android:text="f8" /> 
     </LinearLayout> 
    </LinearLayout> 
</RelativeLayout>