【发布时间】:2015-07-26 07:45:33
【问题描述】:
我正在尝试创建一个欢迎活动,其中包含标题片段 xml 和底部视图片段 xml,其中包含登录按钮。谁能帮助我如何将这两个片段 xml 放入我的activity_main.xml?
这是我的header.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="220dp">
<ImageView
android:id="@android:id/background"
android:layout_width="match_parent"
android:layout_height="220dp"
android:scaleType="centerCrop"
android:src="@drawable/header_bg" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom|right|end"
android:layout_marginStart="@dimen/android_spaces_large"
android:layout_marginEnd="@dimen/android_spaces_large"
android:layout_marginLeft="@dimen/android_spaces_large"
android:layout_marginRight="@dimen/android_spaces_large"
android:layout_marginBottom="@dimen/android_spaces">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/header_title"
style="@style/Header.TitleText" />
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/header_subtitle"
style="@style/Header.SubTitleText" />
</LinearLayout>
<View
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="?android:actionBarSize"
android:background="@layout/header_ab_shadow" />
</FrameLayout>
还有我的fragment_bottomview.xml,它只包含一个按钮。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_gravity="center_horizontal" />
</LinearLayout>
而我的activity_main.xml 看起来像这样
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.windows81.welcomingwithheader.MainActivity"
tools:ignore="MergeRootFrame" />
我不知道我缺少什么或者我做错了什么,任何教程链接都会真正帮助我。
【问题讨论】:
-
使用相对布局。在顶部添加一个片段,相对于它你可以在它下面有另一个片段
-
为什么需要片段?如果您不如何使用片段,则很可能不需要它们...
-
@Raghunandan 我会将 activity_main.xml 上的框架布局更改为相对布局?
-
@pskink 有什么方法可以实现标题并在其底部有按钮?
-
请参阅developer.android.com/training/improving-layouts/…,了解如何在父布局 xml 文件中使用子布局 xml 文件
标签: java android xml android-fragments