1

Я довольно большой нуб, когда дело доходит до андроида, и я застрял в ситуации. How it should beAndroid: наложение таблиц накладки Линейная компоновка

enter image description here

Я хочу, чтобы моя сервировку идти под мою кнопкой, расположенной в линейной компоновке, но он просто перекрывает.

В конце концов, мне нужно будет нажать кнопку, чтобы полностью скрыть стол.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context="eu.agp_it.agpmobilemover.OverviewActivity"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="1.0" 
     android:gravity="center" 
     android:id="@+id/layout_button_today" 
     > 
     <Button 
      android:id="@+id/overview_button_today" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.95" 
      android:layout_width="0dip" 
      android:textSize="20sp" 
      android:text="@string/overview_today" 
      android:gravity="center"/> 
    </LinearLayout> 

<TableLayout 
    android:layout_width="20sp" 
    android:layout_height="fill_parent" 
    android:visibility="visible" 
    > 
    <TableRow> 
     <TextView android:id="@+id/label_depart" android:text="@string/overview_depart_time"/> 
     <TextView /> 
    </TableRow> 

</TableLayout> 
    <LinearLayout 
     android:id="@+id/layout_button_upcoming" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="1.0" 
     android:gravity="center" 
     android:layout_above="@id/layout_button_today"> 
     <Button 
      android:id="@+id/overview_button_upcoming" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.95" 
      android:layout_width="0dip" 
      android:textSize="20sp" 
      android:text="@string/overview_upcoming" 
      android:gravity="center"/> 
    </LinearLayout> 
</RelativeLayout> 
+0

Используйте LinearLayout как root или правильно установите layout_above/layout_below. – Nfear

+0

Использование LinearLayout вместо RelativeLayout и "fill_parent" устарело, если вы используете LinearLayout, тогда android: layout_height = "0dp" android: layout_weight = "1" в TableLayout –

ответ

0

Возьмите две таблицы в

<TableRow> 
    </TableRow> 

<TableRow> 
     </TableRow> 

внутри TableLayout, в котором первая таблица содержит вашу кнопку и второй стол содержит ваш взгляд LinearLayout. Также, как вы пожелаете, вы можете скрыть вторую строку таблицы как желание при нажатии кнопки.

0

Замените свой TableLayout на этот.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent" 
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context="eu.agp_it.agpmobilemover.OverviewActivity"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="1.0" 
     android:gravity="center" 
     android:id="@+id/layout_button_today"> 
     <Button 
      android:id="@+id/overview_button_today" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.95" 
      android:layout_width="0dip" 
      android:textSize="20sp" 
      android:text="@string/overview_today" 
      android:gravity="center"/> 
    </LinearLayout> 

    <TableLayout 
     android:id="@+id/my_table_layout" 
     android:layout_width="20sp" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/layout_button_today" 
     android:visibility="visible" > 
     <TableRow> 
      <TextView android:id="@+id/label_depart" 
       android:text="@string/overview_depart_time"/> 
      <TextView /> 
     </TableRow> 

    </TableLayout> 
    <LinearLayout 
     android:id="@+id/layout_button_upcoming" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="1.0" 
     android:gravity="center" 
     android:layout_below="@id/my_table_layout"> 
     <Button 
      android:id="@+id/overview_button_upcoming" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.95" 
      android:layout_width="0dip" 
      android:textSize="20sp" 
      android:text="@string/overview_upcoming" 
      android:gravity="center"/> 
    </LinearLayout> 
</RelativeLayout> 
+0

Добавлял ли вы только макет? Потому что, если вы это сделали, я попробовал это, и это не сработало и ваше решение. Благодаря! – Madgarr

0

Вы можете использовать под кодом:

<LinearLayout 
     android:id="@+id/layout_button_today" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:weightSum="1.0" > 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight=".05" /> 

      <Button 
       android:id="@+id/overview_button_today" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:layout_weight=".90" 
       android:gravity="center" 
       android:text="@string/overview_today" 
       android:textSize="20sp" /> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight=".05" /> 



    </LinearLayout> 

<TableLayout 
     android:layout_width="20sp" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/layout_button_today" 
     android:layout_above="@+id/layout_button_upcoming" 
     android:visibility="visible" > 
     <TableRow> 
      <TextView android:id="@+id/label_depart" 
        android:text="@string/overview_depart_time"/> 
      <TextView /> 
     </TableRow> 

    </TableLayout> 
     <LinearLayout 
      android:id="@+id/layout_button_upcoming" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="1.0" 
      android:gravity="center" 
      android:layout_above="@id/layout_button_today"> 
      <Button 
       android:id="@+id/overview_button_upcoming" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.95" 
       android:layout_width="0dip" 
       android:textSize="20sp" 
       android:text="@string/overview_upcoming" 
       android:gravity="center"/> 
     </LinearLayout> 

    </RelativeLayout> 
0

Я думаю, что у вас есть 2 кнопки и tableLayut. одна из кнопок находится в верхней части страницы и другая в нижней части страницы. Я предложил этот код:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent" 
     android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     tools:context="eu.agp_it.agpmobilemover.OverviewActivity"> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="1.0" 
      android:gravity="center" 
      android:id="@+id/layout_button_today"> 
      <Button 
       android:id="@+id/overview_button_today" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.95" 
       android:layout_width="0dip" 
       android:textSize="20sp" 
       android:text="@string/overview_today" 
       android:gravity="center"/> 
     </LinearLayout> 

    <TableLayout 
     android:layout_width="20sp" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/layout_button_today" 
     android:layout_above="@+id/layout_button_upcoming" 
     android:visibility="visible" > 
     <TableRow> 
      <TextView android:id="@+id/label_depart" 
        android:text="@string/overview_depart_time"/> 
      <TextView /> 
     </TableRow> 

    </TableLayout> 
     <LinearLayout 
      android:id="@+id/layout_button_upcoming" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="1.0" 
      android:gravity="center" 
      android:layout_above="@id/layout_button_today"> 
      <Button 
       android:id="@+id/overview_button_upcoming" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.95" 
       android:layout_width="0dip" 
       android:textSize="20sp" 
       android:text="@string/overview_upcoming" 
       android:gravity="center"/> 
     </LinearLayout> 
    </RelativeLayout> 
+0

Да, у меня есть две кнопки, я забыл удалить нижний для этого вопроса. Мой план состоит в том, чтобы показать одну таблицу, когда нажата первая кнопка, и одна, когда другая нажата. – Madgarr

+0

Я предложил вам использовать RecyclerView или ListView и динамически добавлять данные после нажатия кнопок. то вы можете уведомить адаптер для изменения списка. –

0

Установить родительский макет как LinearLayout. Ориентация как вертикальная. Также задана видимость расположения таблиц, изначально выведенных в ваш макет. В коде установите Видимость, видимая в вашем методе click.

tableLayout.setVisibility (View.VISIBLE);

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_margin="10dp" 
    android:layout_gravity="center"> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:text="Button"/> 

<TableLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="[email protected]/tableLayout" 
    android:visibility="gone" 
    android:layout_margin="10dp"> 

    <TableRow> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:text="text1"/> 
    </TableRow> 

    <TableRow> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:text="text2"/> 
    </TableRow> 

    </TableLayout> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:text="Button"/> 

    </LinearLayout> 
Смежные вопросы