2012-03-04 200 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> 
相关问题