【发布时间】:2017-02-13 08:27:31
【问题描述】:
我正在尝试在我的应用程序中实现自定义工具栏。我想在左边有 1 个图像和 1 个文本视图,中间有 1 个文本视图,最后有 1 个文本视图。在预览模式下,它看起来像预期的那样: 但是,当我在虚拟设备上启动我的应用程序时,所有视图都与开头对齐:
我的代码:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
tools:context=".OptionListActivity">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:weightSum="3">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@android:drawable/btn_star_big_on"
android:id="@+id/imageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/nameSurname"
android:text="June Office"
android:textColor="@android:color/white"
android:textAlignment="viewStart"
android:layout_weight="1"
android:layout_marginStart="5dp" />
<TextView
android:text="Dec 19, 12:47 PM"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dateTime"
android:textColor="@android:color/white"
android:textAlignment="center"
android:layout_weight="1"/>
<TextView
android:text="415-555-1212"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/number"
android:textColor="@android:color/white"
android:textAlignment="viewEnd"
android:layout_weight="1"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
我需要进行哪些更改才能获得预期的结果?也许有人可以解释一下为什么它在预览模式下看起来不错,而在模拟器上却不正确......
【问题讨论】:
标签: android android-layout android-custom-view android-toolbar