Android在TableRow中的相对布局,后跟线性布局的TableRow

Android在TableRow中的相对布局,后跟线性布局的TableRow,android,android-layout,android-relativelayout,tablelayout,tablerow,Android,Android Layout,Android Relativelayout,Tablelayout,Tablerow,我目前正在开发一个在安卓6上运行的安卓应用程序。我对Android开发完全陌生,但有一点WPF经验,所以我认为XML应该是类似的。以下是我希望视图的外观: 这就是我目前必须解决的XML问题: <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.a

我目前正在开发一个在安卓6上运行的安卓应用程序。我对Android开发完全陌生,但有一点WPF经验,所以我认为XML应该是类似的。以下是我希望视图的外观:

这就是我目前必须解决的XML问题:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_guimain"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:weightSum="2"
    tools:context="indoorpilot.indoorpilot.GUIMain">
    <TableRow>
        <!--android:layout_width="match_parent">-->
        <TextView
            android:id="@+id/textView"
            android:layout_weight="1"
            android:gravity="center_horizontal"
            android:text="Building Label"/>
    </TableRow>


    <TableRow>
        <RelativeLayout
            android:layout_weight="1">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:srcCompat="@drawable/mclaurysecondfloor"
                android:id="@+id/imageView2"/>
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:srcCompat="@android:drawable/presence_online"
                android:="@+id/markerImage"/>

        </RelativeLayout>
    </TableRow>

    <TableRow>
        <LinearLayout
            android:layout_weight="1"
            style="?android:attr/buttonBarStyle">
            <Button
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/contextual_info"
                android:onClick="ShowContextualInformation"/>
            <Button
                style="?android:attr/borderlessButtonStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/scan_button"
                android:onClick="SetRSSIDistanceValues"/>
        </LinearLayout>
    </TableRow>
</TableLayout>


在大型设备(平板电脑)上工作正常,但在Android Studio视图渲染器或任何类型的手机上都无法正常显示。按钮没有显示,因为包含RelativeLayout的TableRow最终占据了整个屏幕…

我在android studio外部完成了这项工作,但如果您需要,我可以为您编辑

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_guimain"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:weightSum="2"
    tools:context="indoorpilot.indoorpilot.GUIMain">

    <TextView
        android:id="@+id/textView"
        android:gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Building Label"/>



        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/textView"
            android:layout_above="@+id/buttons_container"
            app:srcCompat="@drawable/mclaurysecondfloor"
            android:id="@+id/imageView2"/>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView"
            app:srcCompat="@android:drawable/presence_online"
            android:id="@+id/markerImage"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_below="@+id/imageView2"
        android:layout_height="wrap_content"
        android:layout_orientation="horizontal"
        android:id="@+id/buttons_container"
        style="?android:attr/buttonBarStyle">
        <Button
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/contextual_info"
            android:onClick="ShowContextualInformation"/>
        <Button
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/scan_button"
            android:onClick="SetRSSIDistanceValues"/>
    </LinearLayout>

</RelativeLayout>


您不需要
表格布局
。您需要的是一个
RelativeLayout
,它在顶部有一个
TextView
,在下面有两个
ImageView
s,在视图底部有一个包含两个按钮的
LinearLayout
。对于较小的屏幕尺寸,您可能需要一个
滚动视图
,其中包含此
RelativeLayout

我在android studio外部完成了此操作,但如果您需要,我可以帮您编辑

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_guimain"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:weightSum="2"
    tools:context="indoorpilot.indoorpilot.GUIMain">

    <TextView
        android:id="@+id/textView"
        android:gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Building Label"/>



        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/textView"
            android:layout_above="@+id/buttons_container"
            app:srcCompat="@drawable/mclaurysecondfloor"
            android:id="@+id/imageView2"/>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView"
            app:srcCompat="@android:drawable/presence_online"
            android:id="@+id/markerImage"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_below="@+id/imageView2"
        android:layout_height="wrap_content"
        android:layout_orientation="horizontal"
        android:id="@+id/buttons_container"
        style="?android:attr/buttonBarStyle">
        <Button
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/contextual_info"
            android:onClick="ShowContextualInformation"/>
        <Button
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/scan_button"
            android:onClick="SetRSSIDistanceValues"/>
    </LinearLayout>

</RelativeLayout>


您不需要
表格布局
。您需要的是一个
RelativeLayout
,它在顶部有一个
TextView
,在下面有两个
ImageView
s,在视图底部有一个包含两个按钮的
LinearLayout
。对于较小的屏幕尺寸,您可能需要一个包含此
RelativeLayout
ScrollView

使用
RelativeLayout
而不是
TableLayout
作为父级。并将顶行与父行对齐,底行与父行与底行对齐
RelativeLayout
为您提供各种对齐方式。使用
RelativeLayout
而不是
TableLayout
作为父级。并将顶行与父行对齐,底行与父行与底行对齐
RelativeLayout
为您提供各种对齐方式。