Android 相对布局 In TableRow followed by TableRow with Linear Layout
Android Relative Layout In TableRow followed by TableRow with Linear Layout
我目前正在开发 Android 应用程序 运行 Android 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 View Renderer 或任何类型的 phone 上无法正确显示。按钮未显示,因为包含 RelativeLayout 的 TableRow 最终占据了整个屏幕...
我在 android 工作室外完成了此操作,但可能会对您有所帮助,如果您需要,我可以为您编辑。
<?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>
您不需要 TableLayout
。您需要的是一个 RelativeLayout
,顶部有一个 TextView
,下面有两个 ImageView
,视图底部有一个包含两个按钮的 LinearLayout
。对于较小的屏幕尺寸,您可能需要包含此 RelativeLayout
的 ScrollView
。
我目前正在开发 Android 应用程序 运行 Android 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 View Renderer 或任何类型的 phone 上无法正确显示。按钮未显示,因为包含 RelativeLayout 的 TableRow 最终占据了整个屏幕...
我在 android 工作室外完成了此操作,但可能会对您有所帮助,如果您需要,我可以为您编辑。
<?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>
您不需要 TableLayout
。您需要的是一个 RelativeLayout
,顶部有一个 TextView
,下面有两个 ImageView
,视图底部有一个包含两个按钮的 LinearLayout
。对于较小的屏幕尺寸,您可能需要包含此 RelativeLayout
的 ScrollView
。