工具栏覆盖相对布局

时间:2018-05-11 14:09:25

标签: android android-toolbar

我的工具栏覆盖了下面相对布局的部分内容,参见图片

enter image description here 我已经尝试了所有可以考虑的限制因素,但我似乎无法做到正确

布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBackground"
    tools:context="husforbi.com.accenture.husforbi.HomeActivity"
    tools:layout_editor_absoluteY="81dp">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryDark"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"></android.support.v7.widget.Toolbar>

<RelativeLayout
    android:id="@+id/relativeLayout2"
    android:layout_width="match_parent"
    android:layout_height="105dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="80dp"
    android:background="@color/colorPrimary"
    app:layout_constraintBottom_toTopOf="@+id/relativeLayout"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@id/toolbar"
    app:layout_constraintTop_toBottomOf="@id/toolbar"
    android:layout_below="@id/toolbar">

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
        android:id="@+id/sellername"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginStart="14dp"
        android:layout_toEndOf="@+id/imageView2"

        android:textColor="@color/colorPrimaryDark"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/sellerid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignStart="@+id/sellername"
        android:layout_below="@+id/sellername"
        android:textColor="@color/colorPrimaryDark" />

</RelativeLayout>

<RelativeLayout
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="154dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:background="@color/colorPrimary"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/relativeLayout2">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/Newspaper_tag"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/newsCount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textAlignment="textEnd"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="18sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="50dp"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/Calendar_tag"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/calCount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textAlignment="textEnd"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="18sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">

        <Button
            android:id="@+id/suggest"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:background="@android:color/holo_blue_light"
            android:text="@string/Fix_tag"
            android:textColor="@android:color/background_light" />

        <Button
            android:id="@+id/rate"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:background="@android:color/holo_blue_dark"
            android:text="@string/Update_tag"
            android:textColor="@android:color/background_light" />
    </LinearLayout>
</RelativeLayout>

<ProgressBar
    android:id="@+id/indeterminateBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:visibility="invisible"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/relativeLayout" />

我正在使用AppCompatDelegate来创建工具栏,怀疑这会改变什么,但它看起来像这样:

public class HomeActivity extends Activity implements View.OnClickListener, AppCompatCallback {

ProgressBar spinner;

private AppCompatDelegate delegate;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    delegate = AppCompatDelegate.create(this, this);

    //call the onCreate() of the AppCompatDelegate
    delegate.onCreate(savedInstanceState);

    //use the delegate to inflate the layout
    delegate.setContentView(R.layout.activity_home);

    //add the Toolbar
    Toolbar toolbar= (Toolbar) findViewById(R.id.toolbar);
    delegate.setSupportActionBar(toolbar);
    toolbar.setTitle(R.string.HomeActivity);
    delegate.getSupportActionBar().setDisplayShowTitleEnabled(true);
    delegate.getSupportActionBar().setDisplayShowHomeEnabled(true);
    delegate. getSupportActionBar().setIcon(R.mipmap.ic_launcher);

最后,活动的主题如下:

<activity
    android:name=".HomeActivity"
    android:parentActivityName=".BarcodeCaptureActivity"
    android:theme="@style/AppTheme.NoActionBar" />

任何帮助都很有用。

谢谢!

0 个答案:

没有答案