【发布时间】:2013-01-29 17:21:39
【问题描述】:
嘿,我正在尝试创建一个标题,中间有一个图像,右上角有一个按钮。
我找到了这篇文章how to make headers in android with text and buttons like in iOS,以及下面的教程http://www.londatiga.net/it/how-to-create-custom-window-title-in-android/,我能够将图像放在中心并设置背景。但是,无论我做什么,我的按钮都不会出现在右上角。
我试图查看它是否被背景遮盖或超出了屏幕范围,但我找不到问题的原因。
我的 XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/Header"
android:src="@drawable/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff000000"
android:layout_marginTop="5dp"
android:gravity="center_horizontal"/>
<Button
android:id="@+id/lockButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5.0dip"
android:text="TEST"
/>
</LinearLayout>
【问题讨论】:
-
我觉得用ActionBar会更好:developer.android.com/guide/topics/ui/actionbar.html
-
问题是你的线性布局有重心
-
如果我需要支持 2.3 及更高版本,我还能使用操作栏吗?因为我知道它只适用于 3 岁及以上
-
您可以使用 ActionBarSherlock (actionbarsherlock.com) 在 Android 2.3 上获取操作栏。
标签: android android-layout android-button