我想在一个support.v7.widget.Toolbar中使用几个视图,但它看起来像它们都放在水平LinearLayout中一样。我正在寻找更多的东西like this,其中EditText结束溢出菜单,而不是溢出菜单开始的地方。这是我目前的布局:Android的工具栏布局是水平的
<LinearLayout 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"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="250sp"
android:background="@color/primary"
android:gravity="bottom"
android:minHeight="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/button_id"
android:layout_width="40sp"
android:layout_height="40sp"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/url"
android:textColor="@color/accent"
android:textSize="16sp" />
<EditText
android:id="@+id/url_text_field_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:maxLines="1" />
<TextView
android:id="@+id/output_text_view_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/initial_output_text_id"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Here's a screenshot。你可以看到视图符合分享按钮和溢出菜单。标题也隐藏在左侧的意见。 如何在工具栏中为我的视图添加第二行,以便跨越页面的宽度?希望我只是缺少一些小东西,因为我是Android新手。先谢谢您的帮助。
有趣。将它放在工具栏中的好处是什么,而不是从工具栏和下一个视图中没有分隔符? – 2015-01-23 07:48:31
我认为你是对的。我想将它们放在同一个容器中以保持整洁,但我最终将“工具栏”内的视图移动到顶级线性布局中的单独元素中。我为工具栏和视图分配了相同的高程和背景颜色,现在看起来好像它们都是工具栏的一部分。 – 2015-01-24 16:18:43