2011-02-26 79 views
0

我是Android新手,想了解如何获得特定的布局?任何人都可以解释Venmo为Android应用程序的第一个屏幕使用哪种布局(在以下链接中最左边的图片为:http://30.media.tumblr.com/tumblr_lak5yachMv1qcl8xuo1_500.pngAndroid布局帮助(类似于静态)

我试图创建类似于学习用途的布局,但无法正确。下面是我的示例布局代码:

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http``://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:id="@+id/tableLayout1" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
android:background="#fff" 
android:scrollbars="none"> 
<TableRow 
    android:layout_height="wrap_content" 
    android:id="@+id/tableRow1"> 
    <ImageButton 
     android:layout_height="wrap_content" 
     android:id="@+id/imageButton5" 
     android:background="@drawable/icon" 
     android:layout_width="wrap_content" 
     android:layout_weight="1"> 
    </ImageButton> 
</TableRow>  
<TableRow 
    android:layout_height="wrap_content" 
    android:id="@+id/tableRow2"> 
     <TextView 
      android:text="TextView" 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:layout_weight="1"> 
     </TextView> 
</TableRow> 
<TableRow 
    android:id="@+id/tableRow3" 
    android:layout_height="wrap_content" 
    android:layout_margin="0dip" 
    android:padding="0px" 
    android:background="#ff6600"> 
     <ImageButton 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/imageButton1" 
      android:background="@drawable/icon" 
      android:gravity="left" 
      android:layout_weight="1"> 
     </ImageButton> 
     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/imageButton2" 
      android:background="@drawable/icon" 
      android:gravity="right" 
      android:layout_weight="1"> 
     </ImageButton> 
</TableRow> 
<TableRow 
    android:id="@+id/tableRow4" 
    android:layout_height="wrap_content"> 
     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/imageButton3" 
      android:background="@drawable/icon" 
      android:gravity="left" 
      android:layout_weight="1"> 
     </ImageButton> 
     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/imageButton4" 
      android:background="@drawable/icon" 
      android:gravity="right" 
      android:layout_weight="1"> 
     </ImageButton> 
</TableRow> 
</TableLayout> 

我试图弄清楚:

  1. 如何将ImageButton的扩展到屏幕宽度和高度的50%
  2. 如何有一个灵活的ImageButton高度
  3. 如何摆脱边缘上的边距或填充,使ImageButton贴在墙上和彼此之间。
  4. TableLayout是这种布局的好方法吗?
  5. 是否有任何指南为ImageButton创建图像?

谢谢你的帮助。

回答

1

我是Venmo Android应用程序的开发者。

另一个答案建议使用可能效果更好的GridLayout,但Venmo应用程序实际上使用的是表格布局。

以下是对每一个人的问题...

  1. 为了让您的图片缩放等宽,你需要给他们0dp,然后设置的Android layout_width:layout_weight为1
  2. 要获得相同的高度,请将ImageButton的layout_height设置为填充父级,然后将每个表格行的权重设置为1.
  3. 我不完全确定您遇到的边距或填充。如果你像上面提到的那样调整ImageButtons和TableRows的大小,这应该不是问题。
  4. 我不确定这个。 GridLayout可能会更好,但我没有遇到任何使用TableLayout的问题。
  5. 没有任何官方的指导方针,但我建议为您的绘图创建状态,以便用户可以知道他们何时按下按钮。

这里的Venmo应用程序是如何创建的网格一些示例代码:

<TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent"> 

<TableRow android:layout_weight="1"> 

    <ImageButton android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="fill_parent" 
     android:src="@drawable/top_left" 
     android:layout_marginRight="2sp" 
     android:layout_marginBottom="2sp" 
     android:background="@drawable/button"/>    

    <ImageButton android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="fill_parent" 
     android:src="@drawable/top_right" 
     android:layout_marginBottom="2sp" 
     android:background="@drawable/button"/> 

</TableRow> 

<TableRow android:layout_weight="1"> 

    <ImageButton android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="fill_parent" 
     android:src="@drawable/bottom_left" 
     android:layout_marginRight="2sp" 
     android:background="@drawable/button"/> 

    <ImageButton android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="fill_parent" 
     android:src="@drawable/bottom_right" 
     android:background="@drawable/button"/> 

</TableRow></TableLayout> 

请记住,如果屏幕是有史以来身体比你的ImageButton的绘制较小的你会碰到的问题。另外,如果你这样做,你一定会为横向定位创建一个单独的布局。