2013-02-18 42 views
0

我尽量做到这样的事:我怎样才能使这个布局(包含文字和图标的按钮)

enter image description here

到目前为止我的代码是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

     <Button 
      android:id="@+id/btemail" 
      android:layout_width="130dp" 
      android:layout_height="130dp" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:layout_marginBottom="45dp" 
      android:layout_marginLeft="34dp" 
      android:drawableTop="@drawable/mail" 
      android:text="E-mail" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 

     <Button 
      android:id="@+id/btcharts" 
      android:layout_width="130dp" 
      android:layout_height="130dp" 
      android:layout_above="@+id/btemail" 
      android:layout_alignLeft="@+id/btemail" 
      android:background="@android:color/transparent" 
      android:drawableTop="@drawable/chart" 
      android:drawablePadding="-35dp" 
      android:text="Charts" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 

     <Button 
      android:id="@+id/bthistory" 
      android:layout_width="130dp" 
      android:layout_height="130dp" 
      android:layout_alignBaseline="@+id/btemail" 
      android:layout_alignBottom="@+id/btemail" 
      android:layout_toRightOf="@+id/btemail" 
      android:drawableTop="@drawable/list" 
      android:text="History" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 

     <Button 
      android:id="@+id/btimport" 
      android:layout_width="130dp" 
      android:layout_height="130dp" 
      android:layout_alignLeft="@+id/bthistory" 
      android:layout_alignTop="@+id/btcharts" 
      android:drawableTop="@drawable/add" 
      android:text="New Measurement" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 

    </RelativeLayout> 

我的看法是这样的:

enter image description here

可以这样用relativ完成仅查看还是应该使用gridview?

如果我设置了android:layout_height =“130dp”,但图标对于不同的屏幕有不同的尺寸“50x50 66x66 98x98 130x130”。对于不同的屏幕会有问题吗? 有没有办法实现它动态?

怎样把图标中心垂直和图表按钮的水平????因为现在它是多一点了中心的..

回答

2

我建议你使用RelativeLayout文本和背景和按钮放置到将被嵌套在它的父TableLayoutGridLayout(在适当的利润) - RelativeLayout

1

的DP或浸度量是在密度160或MDPI的像素数,所以,你可以在你的布局文件夹中MDPI像素的大小及比例的其他尺寸如下表:

  • xhdpi:2.0
  • HDPI:1.5
  • MDPI:1.0(基线)
  • LDPI:0.75

有关的详细信息见thisthis

编辑:我相信做这种布局的最好方法是让所有的按钮都是线性布局,并且有一个相对布局作为根,并且通过重力或者类似的方式来对齐线性布局。

我的例子:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="42dp" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/btcharts" 
      android:layout_width="130dp" 
      android:layout_height="130dp" 
      android:drawablePadding="-35dp" 
      android:drawableTop="@drawable/chart" 
      android:text="Charts" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 

     <Button 
      android:id="@+id/btimport" 
      android:layout_width="130dp" 
      android:layout_height="130dp" 
      android:drawableTop="@drawable/add" 
      android:text="New Measurement" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dp" > 

     <Button 
      android:id="@+id/btemail" 
      android:layout_width="130dp" 
      android:layout_height="130dp" 
      android:drawableTop="@drawable/mail" 
      android:text="E-mail" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 

     <Button 
      android:id="@+id/bthistory" 
      android:layout_width="130dp" 
      android:layout_height="130dp" 
      android:drawableTop="@drawable/list" 
      android:text="History" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 
    </LinearLayout> 
</LinearLayout> 

我不知道,这一切都对准,因为我没有你的可绘制在这里,但我能想到的,你可以从这个提高,也是你的“图表“按钮是不同的,因为它具有透明背景。

+0

我都为不同规模的necesery图标.. 我只是想完成的2x2按钮网格状的图片... – oikonomopo 2013-02-18 19:21:18

+0

我误解你的问题,然后,看到我会在做代码编辑您的案件。 – 2013-02-19 11:31:40

相关问题