简体   繁体   English

如何在tablelayout底部显示按钮?

[英]how to show buttons in bottom of the tablelayout?

I have download sample tablelayout source code it's working fine. 我已下载示例tablelayout源代码,它工作正常。 I am trying to show four image button in bottom of the table layout but still it,s not working. 我试图在表格布局的底部显示四个图像按钮但仍然没有工作。

Current image: 当前图片: 在此输入图像描述

I am trying to show this 4 buttons in bottom of the table layout: 我试图在表格布局的底部显示这4个按钮: 在此输入图像描述

This is my code: i wish to merge my source code in my table layout bottom please help me. 这是我的代码:我希望在我的表格布局底部合并我的源代码请帮助我。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/ttt3"
        android:layout_width="150dip"
        android:layout_height="40dip"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:background="@drawable/bt_blue" />

    <Button
        android:id="@+id/ttt2"
        android:layout_width="150dip"
        android:background="@drawable/bt_yellow"
        android:layout_height="40dip"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="20dp"
        android:layout_toLeftOf="@+id/ttt3"
         />

    <Button
        android:id="@+id/ttt1"
        android:layout_width="150dip"
       android:background="@drawable/bt_green"
        android:layout_height="40dip"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="20dp"
        android:layout_toLeftOf="@+id/ttt2"
         />

    <Button
        android:id="@+id/ttt0"
        android:layout_width="150dip"
        android:layout_height="40dip"
        android:background="@drawable/bt_red"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:gravity="bottom"
         />

</RelativeLayout>

table code: 表格代码:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:shrinkColumns="*"
    android:stretchColumns="*">
    <TableRow
        android:id="@+id/tableRow4"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:gravity="center_horizontal">
        <TextView
            android:id="@+id/textView9"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:typeface="serif"
            android:textSize="18dp"
            android:text="Weather Table"
            android:gravity="center"
            android:layout_span="6"></TextView>
    </TableRow>
    <TableRow
        android:id="@+id/tableRow1"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
        <TextView
            android:id="@+id/TextView04"
            android:text=""></TextView>
        <TextView
            android:id="@+id/TextView04"
            android:text="Feb 7"
            android:textStyle="bold"
            android:typeface="serif"></TextView>
        <TextView
            android:id="@+id/TextView03"
            android:text="Feb 8"
            android:textStyle="bold"
            android:typeface="serif"></TextView>
        <TextView
            android:id="@+id/TextView02"
            android:text="Feb 9"
            android:textStyle="bold"
            android:typeface="serif"></TextView>
        <TextView
            android:id="@+id/TextView01"
            android:text="Feb 10"
            android:textStyle="bold"
            android:typeface="serif"></TextView>
        <TextView
            android:text="Feb 11"
            android:id="@+id/textView1"
            android:textStyle="bold"
            android:typeface="serif"></TextView>
    </TableRow>
    <TableRow
        android:layout_height="wrap_content"
        android:id="@+id/tableRow2"
        android:layout_width="match_parent">
        <TextView
            android:text="Day High"
            android:id="@+id/textView2"
            android:textStyle="bold"></TextView>
        <TextView
            android:id="@+id/textView3"
            android:text="28°F"
            android:gravity="center_horizontal"></TextView>
        <TextView
            android:text="26°F"
            android:id="@+id/textView4"
            android:gravity="center_horizontal"></TextView>
        <TextView
            android:text="23°F"
            android:id="@+id/textView5"
            android:gravity="center_horizontal"></TextView>
        <TextView
            android:text="17°F"
            android:id="@+id/textView6"
            android:gravity="center_horizontal"></TextView>
        <TextView
            android:text="19°F"
            android:id="@+id/textView7"
            android:gravity="center_horizontal"></TextView>
    </TableRow>
    <TableRow
        android:layout_height="wrap_content"
        android:id="@+id/tableRow2"
        android:layout_width="match_parent">
        <TextView
            android:text="Day Low"
            android:id="@+id/textView2"
            android:textStyle="bold"></TextView>
        <TextView
            android:text="15°F"
            android:id="@+id/textView3"
            android:gravity="center_horizontal"></TextView>
        <TextView
            android:text="14°F"
            android:id="@+id/textView4"
            android:gravity="center_horizontal"></TextView>
        <TextView
            android:text="3°F"
            android:id="@+id/textView5"
            android:gravity="center_horizontal"></TextView>
        <TextView
            android:text="5°F"
            android:id="@+id/textView6"
            android:gravity="center_horizontal"></TextView>
        <TextView
            android:text="6°F"
            android:id="@+id/textView7"
            android:gravity="center_horizontal"></TextView>
    </TableRow>
    <TableRow
        android:id="@+id/tableRow3"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:gravity="center">
        <TextView
            android:id="@+id/textView8"
            android:text="Conditions"
            android:textStyle="bold"></TextView>
        <ImageView
            android:id="@+id/imageView1"
            android:src="@drawable/hot"></ImageView>
        <ImageView
            android:id="@+id/imageView2"
            android:src="@drawable/pt_cloud"></ImageView>
        <ImageView
            android:id="@+id/imageView3"
            android:src="@drawable/snow"></ImageView>
        <ImageView
            android:id="@+id/imageView4"
            android:src="@drawable/lt_snow"></ImageView>
        <ImageView
            android:id="@+id/imageView5"
            android:src="@drawable/pt_sun"></ImageView>
    </TableRow>
</TableLayout>

Provded you want to put buttons at the bottom of the screen, you can have a setup like this: 如果您希望将按钮放在屏幕底部,您可以进行如下设置:

<RelativeLayout>
    <RelativeLayout layout_alignParentBottom="true" android:id="buttons">
        <!-- your buttons go here -->
    </RelativeLayout>

    <TableLayout layout_height="match_parent" layout_above="buttons">
        <!-- your table content -->
    </TableLayout>
</RelativeLayout>

Note that this is pseudo-code. 请注意,这是伪代码。 You will need to actually specify all the required attributes on the XML elements. 您需要实际指定XML元素上的所有必需属性。

if you want the it on the button of the screen just wrap the table inside an LinearLayout. 如果你想在屏幕的按钮上将它包装在LinearLayout内。 after the table is done you can add you Relative layout by copy & paste it or by using 表格完成后,您可以通过复制粘贴或使用来添加相对布局

you can achieve using relative layout and by putting layout weight. 你可以实现使用相对布局和布局权重。 Here is an example 这是一个例子

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/app_background"
    android:orientation="horizontal"
    android:padding="10dip"
    android:id="@+id/biometric_layout">



<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"    
    android:layout_marginTop="1dp" 
    android:layout_below="@+id/trans_Heading"
    android:id="@+id/headingRow"
    >   

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"    
    android:weightSum="100"    
    >

 <ScrollView
        android:id="@+id/scrollViewDialog"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        android:isScrollContainer="false" 
        android:layout_gravity="center"
        android:orientation="vertical"
        android:layout_weight = "70"
        > 

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
       <ImageView
                android:id="@+id/ibTermsConditions"
                android:layout_width="match_parent"
                android:layout_height="match_parent" 
                android:src="@drawable/bio_finger_scan_image" 
                />       
    </LinearLayout> 
  </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_weight = "30"
        >

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"            
            android:layout_marginTop="15dp"
            android:gravity="center"
            android:orientation="horizontal"
            >
    <Button
        android:id="@+id/btBack"
        android:layout_width="wrap_content"
        android:layout_height="25dp"
        android:text="Back"        
        android:textSize="15sp" />

     <Button
        android:id="@+id/btNext"
        android:layout_width="wrap_content"
        android:layout_height="25dp"        
        android:text="Next>"
        android:textColor="#ffffff"
        android:textSize="15sp" />

      <Button
        android:id="@+id/btCancel"
        android:layout_width="wrap_content"
        android:layout_height="25dp"
        android:text="Cancel"
        android:textColor="#ffffff"
        android:textSize="15sp" />
     </LinearLayout>

    </LinearLayout>     

    </LinearLayout>
   </LinearLayout>

</RelativeLayout>

If you want the button to be placed at the bottom of the screen replace your linear layout with relative layout and place the buttons in that. 如果您希望将按钮放在屏幕底部,请用相对布局替换线性布局,并将按钮放在其中。

    <RelativeLayout>
        <RelativeLayout 
    layout_alignParentBottom="true" >
           <!-- Your Button is to be placed here -->
        </RelativeLayout>
    </TableLayout>
//Your table contents
    </TableLayout>
    </RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM