在我ToolBar
的 withandroid:padding=0dp
中,在其中我有一个LinearLayout
with android:width=match_parent
and android:layout_marginLeft="0dp"
。因此,至少在宽度方面,Toolbar
(在本例中为黑色)的任何部分都不应显示在LinearLayout
(在此 SSCCE 中为红色)的侧面。
问题是工具栏显示在子 LinearLayout 的左侧。如何使 LinearLayout 跨越整个工具栏,以便工具栏的任何部分都不显示?
MainActivity.java:
package tests.example_one;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@SuppressLint("NewApi")
public class MainActivity extends AppCompatActivity {
private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.mainActivity_appBar);
setSupportActionBar(toolbar);
}
}
资源/布局/activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/fullBackgroundPadding" >
<include layout="@layout/app_bar"
android:id="@+id/mainActivity_appBar" />
</LinearLayout>
资源/布局/app_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/appBarHeight"
android:background="#000"
android:padding="0dp" >
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F44336"
android:layout_marginLeft="0dp">
</LinearLayout>
</android.support.v7.widget.Toolbar>
res/values/dimens.xml
<resources>
<dimen name="fullBackgroundPadding">8dp</dimen>
<!-- App Bar -->
<dimen name="appBarHeight">48dp</dimen>
</resources>