Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android布局帮助(类似于venmo)_Android_Layout_Tablelayout - Fatal编程技术网

Android布局帮助(类似于venmo)

Android布局帮助(类似于venmo),android,layout,tablelayout,Android,Layout,Tablelayout,我是Android新手,正在努力理解如何正确地进行特定的布局?有人能解释一下Venmo在Android应用程序的第一个屏幕上使用的布局吗(最左边的图片在下面的链接:) 我试图创建一个类似的布局,用于学习目的,但不能得到它的权利。以下是我的布局代码示例: <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http``://schemas.android.com/apk/res/android" a

我是Android新手,正在努力理解如何正确地进行特定的布局?有人能解释一下Venmo在Android应用程序的第一个屏幕上使用的布局吗(最左边的图片在下面的链接:)

我试图创建一个类似的布局,用于学习目的,但不能得到它的权利。以下是我的布局代码示例:

<?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>

我想弄明白的是:

  • 如何将ImageButton缩放到屏幕宽度和高度的50%
  • 如何使ImageButton具有灵活的高度
  • 如何去除边缘上的边距或填充物,使ImageButton粘在墙上并彼此粘在一起
  • 对于这种布局,TableLayout是一种很好的方法吗
  • 是否有为ImageButton创建图像的指导原则

  • 谢谢你的帮助。

    改用网格布局,至于边距,有一个属性控制它。如果你只有4幅图像,如果你使用网格布局,它们将适当渲染(你想要的50%s)。gridView教程实际上相当不错。看一看。

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

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

    下面是每个问题的答案

  • 要使图像缩放到相等的宽度,您需要给它们一个0dp的布局宽度,然后将android:layout\u weight设置为1
  • 要获得相等的高度,请将ImageButton的布局高度设置为“填充父对象”,然后将每个表行的权重设置为1
  • 我不完全确定你会遇到什么样的边际或填充。如果像我上面提到的那样调整ImageButtons和TableRows的大小,这应该不是问题
  • 我不确定这件事。GridLayout可能工作得更好,但我在使用TableLayout时没有遇到任何问题
  • 没有任何官方的指导方针,但我建议为您的绘图创建状态,以便用户可以知道他们何时按下按钮
  • 以下是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的可绘制尺寸,您将遇到问题。此外,如果您这样做,您肯定会希望为横向方向制作一个单独的布局