首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android studio中表格布局与线性布局重叠

Android studio中表格布局与线性布局重叠
EN

Stack Overflow用户
提问于 2018-08-30 02:50:35
回答 2查看 176关注 0票数 -1

我在按正确的顺序排列我的内容时遇到了问题。当我在模拟器中测试我的应用程序时,我发现表布局与线性布局重叠。我已经尝试了一些解决方案,但都没有奏效。

代码语言:javascript
复制
 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/table_background2" android:layout_width="match_parent" android:layout_height="match_parent">
    <RelativeLayout android:gravity="center" android:id="@+id/headerpicture" android:background="@color/loginheader" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true">
        <TextView android:textSize="20sp" android:textColor="#fff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:text="@string/fixed_header"/>
        <ImageView android:id="@+id/imgLeftBack" android:layout_width="35dp" android:layout_height="35dp" android:src="@drawable/arrow_left_green" android:layout_alignParentRight="true" android:onClick="goBack" android:contentDescription="@string/empty"/>
    </RelativeLayout>
    <RelativeLayout android:gravity="center" android:id="@+id/footer" android:background="@color/loginheader" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true">


        <TextView android:textColor="#fff" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:text="@string/copyright" android:ems="8"/>
    </RelativeLayout>
    <TableLayout android:layout_gravity="top" android:id="@+id/tableLayout1" android:background="@drawable/gradient" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_marginRight="5dp" android:layout_below="@+id/headerpicture">
        <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <TextView android:textColor="@color/list_item_text" android:ellipsize="none" android:layout_gravity="top" android:id="@+id/textViewUsernamePicture" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="@dimen/text_view_marginLeft" android:layout_marginTop="@dimen/text_view_marginTop" android:text="@string/pre_election_usernameLbl" android:layout_weight="1"/>
            <EditText android:layout_gravity="left|center_vertical|center_horizontal|center" android:id="@+id/txtUsernamePicture" android:layout_width="wrap_content" android:layout_height="@dimen/edit_text_height" android:layout_marginLeft="@dimen/text_view_marginLeft" android:ems="8" android:layout_weight="3" android:inputType="text"/>
        </TableRow>
        <TableRow android:layout_marginBottom="10dp" android:id="@+id/tableLayout2Row9" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <EditText android:gravity="top|left|center_vertical|center_horizontal|center" android:layout_gravity="left|center_vertical|center_horizontal|center" android:id="@+id/txtTitle" android:layout_width="wrap_content" android:layout_height="wrap_content"  android:layout_weight="3" android:inputType="text" android:hint="Incident Title" android:layout_marginLeft="@dimen/table_marginLeft"/>
        </TableRow>
    </TableLayout>
    <ImageView android:layout_marginBottom="0dp" android:layout_gravity="center" android:id="@+id/ImgPicture" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/text_view_marginTop" android:src="@drawable/picture_placeholder" android:layout_below="@+id/tableLayout1" android:contentDescription="@string/empty"/>

    <TableLayout android:layout_gravity="top" android:id="@+id/tableLayout2" android:background="@drawable/gradient" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_marginRight="5dp" android:layout_below="@+id/ImgPicture">

        <TableRow android:layout_marginBottom="10dp" android:id="@+id/tableLayout2Row13" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <TextView android:textColor="@color/list_item_text" android:ellipsize="none" android:layout_gravity="top" android:id="@+id/textViewPriorityIncident" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="@dimen/text_view_marginLeft" android:layout_marginTop="@dimen/text_view_marginTop" android:text="@string/incident_priorityLbl" android:layout_weight="1"/>
            <Spinner android:entries="@array/incident_priority_arrays" android:id="@+id/spinnerPriorityIncident" android:layout_width="match_parent" android:layout_height="wrap_content" android:prompt="@string/incident_priority_prompt"/>
        </TableRow>

        <TableRow android:layout_marginBottom="10dp" android:id="@+id/tableLayout2Row5" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <EditText android:gravity="top|left|center_vertical|center_horizontal|center" android:layout_gravity="left|center_vertical|center_horizontal|center" android:id="@+id/txtCommentsIncident" android:scrollbars="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/table_marginLeft" android:lines="4" android:minLines="3" android:ems="8" android:maxLength="@string/comments_length" android:layout_weight="3" android:inputType="textMultiLine" android:hint="Comment"/>

        </TableRow>
    </TableLayout>

    <LinearLayout android:id="@+id/btnsHolder" android:layout_gravity="center" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tableLayout2" android:layout_above="@id/footer">
        <Button android:background="@color/red" android:textColor="@color/redtextxolor"  android:tint="@color/redtextxolor" android:id="@+id/btnSaveImage" android:paddingLeft="@dimen/btn_padding_left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="@string/btnBack" android:drawableLeft="@android:drawable/ic_media_previous" android:onClick="goBack"/>
         <Button  android:background="@color/btn" android:textColor="@color/btntextcolor"  android:tint="@color/btntextcolor"   android:layout_gravity="center" android:id="@+id/btnTakePicture" android:paddingLeft="10sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="@string/btnSnap" android:drawableLeft="@android:drawable/ic_menu_camera"  android:onClick="captureImage"/>
         <Button  android:background="@color/snap" android:textColor="@color/white"  android:tint="@color/white"   android:layout_gravity="center" android:id="@+id/btnSendPicture" android:paddingLeft="10sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="@string/btnSendSnap" android:drawableLeft="@android:drawable/ic_menu_send" android:onClick="sendForm"/>

     </LinearLayout>


</RelativeLayout>
EN

回答 2

Stack Overflow用户

发布于 2018-08-30 03:08:03

首先,这是我见过的最糟糕的格式,lol buuut在线性布局中,只需将其设置为在表格布局下

像这样

代码语言:javascript
复制
<TableLayout
    android:id="@+id/mytable"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</TableLayout>


<LinearLayout

    android:id="@+id/mylinear"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/mytable">
</LinearLayout>

注意android:layout_below="@+id/mytable">。这是我为表视图提供的id,这样它们就不会重叠,现在在您的代码中,这意味着您必须为表布局提供id才能做到这一点

不要介意高度和宽度,我给出了线性视图,如果layout_below,剩下的就是我按enter来填充

票数 0
EN

Stack Overflow用户

发布于 2018-08-30 03:22:36

代码语言:javascript
复制
<LinearLayout
 android:orientation="horizontal"
 android:background="@drawable/gradient"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_marginLeft="5dp"
 android:layout_marginTop="5dp"
 android:layout_marginRight="5dp" >
  <Spinner 
    android:entries="@array/incident_priority_arrays"
    android:id="@+id/spinnerPriorityIncident"
    android:layout_width="wrap_content"\ 
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:prompt="@string/incident_priority_prompt"/>
 <TextView 
    android:textColor="@color/list_item_text" 
    android:ellipsize="none"
    android:id="@+id/textViewPriorityIncident"
    android:layout_gravity="center_vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_marginLeft="@dimen/text_view_marginLeft" 
    android:layout_marginTop="@dimen/text_view_marginTop" 
    android:text="@string/incident_priorityLbl" />
</LinearLayout>


<LinearLayout 
    android:layout_marginBottom="10dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:orientation="vertical">
<EditText 
    android:gravity="center" 
    android:id="@+id/txtCommentsIncident"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/table_marginLeft" 
    android:lines="4" 
    android:minLines="3" 
    android:ems="8" 
    android:maxLength="@string/comments_length" 
    android:inputType="textMultiLine"
    android:hint="Comment"/>

</LinearLayout>

<LinearLayout android:id="@+id/btnsHolder"
    android:layout_gravity="center"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_below="@+id/tableLayout2"
    android:layout_above="@id/footer">
        <Button
        android:background="@color/red"
        android:textColor="@color/redtextxolor" 
        android:tint="@color/redtextxolor" 
        android:id="@+id/btnSaveImage"
        android:paddingLeft="@dimen/btn_padding_left" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="10dp"
        android:text="@string/btnBack"
        android:drawableLeft="@android:drawable/ic_media_previous"
        android:onClick="goBack"/>
         <Button 
         android:background="@color/btn"
         android:textColor="@color/btntextcolor"
         android:tint="@color/btntextcolor"
         android:layout_gravity="center" 
         android:id="@+id/btnTakePicture"
         android:paddingLeft="10sp"
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content"
         android:layout_margin="10dp"
         android:text="@string/btnSnap"
         android:drawableLeft="@android:drawable/ic_menu_camera" 
         android:onClick="captureImage"/>
         <Button 
         android:background="@color/snap"
         android:textColor="@color/white"
         android:tint="@color/white"  
         android:layout_gravity="center"
         android:id="@+id/btnSendPicture"
         android:paddingLeft="10sp" 
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_margin="10dp"
         android:text="@string/btnSendSnap"
         android:drawableLeft="@android:drawable/ic_menu_send" 
         android:onClick="sendForm"/>

     </LinearLayout>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52084295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档