简体   繁体   English

操作栏中的自定义布局

[英]Custom layout in action bar

I'm trying to create a custom layout to put as the action bar. 我正在尝试创建一个自定义布局以放置为操作栏。 The layout needs to contain an image on the far right, TextView in the middle, and an ImageView on the far left. 布局需要在最右边包含一个图像,在中间包含一个TextView,在最左边包含一个ImageView。 I can't seem to center the TextView. 我似乎无法将TextView居中。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#aaaa0000"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_menu_back"
        android:layout_gravity="center_horizontal" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="298dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="TextView" />

Use RelativeLayout, it's a lot better, I think this should work 使用RelativeLayout会更好,我认为这应该可以

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
      android:background="#aaaa0000" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_menu_back"
    android:layout_alignParentLeft="true"

    />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:text="TextView" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/something_else"
    android:layout_alignParentRight="true"

    />
</RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM