我正在尝试使用以下代码插入标题栏。我试着在最左边和最右边保留两个按钮。但标题栏上看不到按钮 TextView在这里用作标题栏,即:
<TextView
android:layout_width="fill_parent"
android:layout_height="50px"
android:text="CAMERA"
android:gravity="center_horizontal"
android:background="#4C7D7E"
>
</TextView>
按钮代码:
&LT;
Button
android:id="@+id/save"
android:layout_width="144px"
android:layout_height="37px"
android:text="save"
android:layout_x="7px"
android:layout_y="388px"
>
</Button>
<Button
android:id="@+id/send"
android:layout_width="144px"
android:layout_height="37px"
android:text="send"
android:layout_x="158px"
android:layout_y="388px"
>
</Button>
无法猜测。任何人都可以帮助我
提前致谢
答案 0 :(得分:0)
这些物品属于哪种父母?就个人而言,我可能会使用TableLayout然后使用重力来定位我希望它们出现的对象。使用weight标签设置titleBar上对象的间距。
答案 1 :(得分:0)
您应该定义这样的布局并将其设置为标题栏。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/titlebar"
android:layout_width="fill_parent" android:layout_height="80dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id="@+id/save"
android:layout_width="144px"
android:layout_height="37px"
android:text="save"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/titleText"
android:text="right" />
<Button
android:id="@+id/send"
android:layout_width="144px"
android:layout_height="37px"
android:text="send"
android:layout_gravity="right"/>
</LinearLayout>
答案 2 :(得分:0)
使用这个并告诉我这对你有用吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/titlebar"
android:layout_width="fill_parent" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" android:weightSum="3">
<Button
android:layout_weight="1"
android:id="@+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="save"/>
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/titleText"
android:text="right" />
<Button
android:layout_weight="1"
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send"
android:layout_gravity="right"/>
</LinearLayout>
答案 3 :(得分:0)
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@drawable/main_bg">
<RelativeLayout android:id="@+id/Rel_Top"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#4C7D7E">
<Button android:id="@+id/Btn_Back"
android:layout_width="wrap_content"android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_marginLeft="10dip"
android:layout_centerVertical="true" android:background="@drawable/settings"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Text_Title"
android:text="Title" android:layout_centerInParent="true"
android:singleLine="true"/>
<Button android:id="@+id/Btn_Search"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_marginRight="10dip"
android:layout_centerVertical="true" android:background="@drawable/search" />
</RelativeLayout>
</RelativeLayout>
If you want to change the background color then change the background color in <RelativeLayout android:id="@+id/Rel_Top"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#4C7D7E">