【问题标题】:Android TableLayout - Text View and Button inside the same columnAndroid TableLayout - 同一列内的文本视图和按钮
【发布时间】:2015-03-19 04:53:20
【问题描述】:

这是我的 TableLayout 的代码:

<TableLayout 
    android:layout_width="1200dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="40dp"
    android:layout_marginLeft="40dp" >
        
    <TableRow>
        <TextView
           	android:text="ADDRESS"
            android:background="@drawable/cell_shape"
            android:textColor="@color/white"
            android:layout_weight="1"
            style="TableTitle" />

        <TextView
            android:text="TENANCY"
            android:background="@drawable/cell_shape"
            android:textColor="@color/white"
            android:layout_weight="1"
          	style="TableTitle" />
        
        <TextView
            android:text="LOCATION"
            android:background="@drawable/cell_shape"
            android:textColor="@color/white"
            android:layout_weight="5"
           	style="TableTitle" />
         
        <TextView
            android:text="NAME"
            android:background="@drawable/cell_shape"
            android:textColor="@color/white"
            android:layout_weight="1"
          	style="TableTitle" />
        
        <TextView
            android:text="SELECTION"
            android:background="@drawable/cell_shape"
            android:textColor="@color/white"
            android:layout_weight="1"
			style="TableTitle" />
        
    </TableRow>

那么我的drawable/cell_shape如下:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape= "rectangle"
    android:name="@+id/rec1"  >
   
        <solid android:color="#30383F"
               android:padding="10dp" />
        <scale 
               android:scaleHeight="200"
               android:scaleWidth="200" />
        
        <stroke 
               android:width="1dp"  
               android:color="#D9D9D6" />
        <padding 
               android:left="10dp"  
               android:top="10dp" 
               android:right="10dp"  
               android:bottom="10dp" />

</shape>

我可以很好地设置表格,但我的问题是我是否还可以在位于文本视图右侧的列中包含一个按钮。这可能吗?

例如,在第一列中,我希望它说“地址”,然后在右侧几个像素处显示一个按钮,所有这些都在同一列内。感谢您的帮助!

【问题讨论】:

    标签: android button drawable shape tablelayout


    【解决方案1】:

    您可以包含相对或线性布局以在每列中包含按钮和文本

     <TableRow>
    <Relativelayout
       android:layout_width="match_parent"
        android:layout_height="match_parent">
    <TextView
                android:text="ADDRESS"
                android:background="@drawable/cell_shape"
                android:textColor="@color/white"
                 android:layout_width="wrap_content"
        android:layout_height="wrap_content"
                style="TableTitle" />
    
    <Button 
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
    
    
               android:id="@+id/addbtn"
                android:clickable="false"
    
    
                 android:layout_alignParentRight="true"      
                />
    </Relativelayout>
    

    【讨论】:

    • 我会 UP 你的答案,但我没有足够的代表,介意 UP'ing 我的问题吗?
    • 当我得到 15 个代表时,我会回复你的答案
    猜你喜欢
    • 1970-01-01
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-26
    • 1970-01-01
    相关资源
    最近更新 更多