【发布时间】:2017-03-26 10:00:17
【问题描述】:
我目前正在开发一个在 Android 6 上运行的 Android 应用程序。我对 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 View Renderer 或任何类型的手机上都无法正常显示。按钮未显示,因为包含 RelativeLayout 的 TableRow 最终占据了整个屏幕...
【问题讨论】:
-
使用
RelativeLayout代替TableLayout作为父级。并将顶行与父级对齐,底行与父级底部对齐。RelativeLayout为您提供各种对齐方式。
标签: android android-layout android-relativelayout tablelayout tablerow