Макет таблицы перекрывается Linear Layout в студии Android - PullRequest
0 голосов
/ 29 августа 2018

У меня проблема с выравниванием содержимого в правильном порядке. Когда я тестировал свое приложение в эмуляторе, я обнаружил, что макет таблицы перекрывает линейный макет. Я пробовал некоторые решения, но ни одно не помогло.

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

Ответы [ 2 ]

0 голосов
/ 29 августа 2018
<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 голосов
/ 29 августа 2018

Во-первых, это худшее форматирование, которое я когда-либо видел lol buuut внутри линейного макета, просто установите его под макет таблицы

как это

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

обратите внимание на андроид: layout_below = "@ + id / mytable">. это идентификатор, который я дал табличному представлению, просто сделайте это, тогда они не должны перекрываться, теперь в вашем коде это будет означать, что вам нужно будет дать идентификатор макету таблицы, чтобы сделать это

не обращайте внимания на высоту и ширину. Я дал линейному виду все, о чем вам следует беспокоиться, если layout_below, остальное только я нажал Enter, чтобы заполнить

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...