对于Android而言,我是一个相当大的菜鸟,我陷入困境。 How it should be
我希望我的表格布局位于线性布局中的按钮下,但它只是重叠。
最终我必须能够点击按钮完全隐藏表格。
<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 :(得分:0)
将两张表格作为
<TableRow>
</TableRow>
<TableRow>
</TableRow>
TableLayout中的,其中第一个表包含您的按钮,第二个表包含您的linearlayout视图。您也可以根据需要隐藏第二个表格行。
答案 1 :(得分: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>
答案 2 :(得分: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>
答案 3 :(得分: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>
答案 4 :(得分:0)
将父布局设置为LinearLayout。 方向垂直。 同时设置最初在布局中消失的表格布局的可见性。 在代码中,在点击方法
中设置可见性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="+@id/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>