折叠工具栏和子LinearLayout之间的额外空间

时间:2017-07-10 06:06:59

标签: android android-collapsingtoolbarlayout

我试图实现一个半透明的折叠工具栏,底部有一条实线,它与工具栏一起折叠。然而,这条线和屏幕的末端之间存在这种奇怪的间隙/空间,我不知道它来自哪里。

我已经尝试插入app:contentInsetStart="0dp"android:contentInsetStart="0dp",但它仍然没有摆脱边际。

截图:

Screenshot 1

Screenshot 2

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/background">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:background="@android:color/transparent"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/ctbar_background"
        app:contentScrim="@android:color/transparent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:contentInsetStart="0dp"
        android:contentInsetStart="0dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:gravity="center"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tvreqno"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="17049"
                android:textColor="#ffffff"
                android:textSize="75sp" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_marginRight="10dp"
                    android:src="@drawable/ic_pending" />

                <TextView
                    android:id="@+id/tvstatus"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="Assigned"
                    android:textColor="#ffffff"
                    android:textSize="35sp" />

            </LinearLayout>

            <View
                android:layout_width="40dp"
                android:layout_height="1dp"
                android:layout_marginBottom="50dp"
                android:layout_marginTop="25dp"
                android:background="#ffffff" />

        </LinearLayout>


        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/transparent"
            app:layout_collapseMode="pin" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_gravity="bottom"
            android:background="#56dafe"
            app:layout_collapseMode="pin" />

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingTop="10dp">

        <include layout="@layout/details_work_order2" />

    </LinearLayout>


</android.support.v4.widget.NestedScrollView>

我的活动:

public class WorkOrderDetailsActivity extends MMSAppCompatActivity
    implements AsyncResponseHelper {

  private CollapsingToolbarLayout collapsingToolbarLayout = null;
  private Toolbar toolbar = null;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.collapsing_toolbar); //if there is no valid saved instance for authentication, go to the log in page
    data = getIntent().getExtras();
    cid = StringHelper.toStringSafe(String.valueOf(data.getInt("Cid")));
    thisView = findViewById(android.R.id.content);
    status = StringHelper.toStringSafe(String.valueOf(data.getString("ExtraItemStatus")));
    statusEnum = StatusHelper.getStatusEnum(status);
    activityHelper = new ActivityHelper(this, this, thisView, cid,
        DataHolder.WorkOrderTableName, attachmentIsExternalTable, attachments, signatureNames);
    thisActivity = this;
    thisContext = this;

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    thisActivity.setSupportActionBar(toolbar);
    ActionBar actionBar = thisActivity.getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbarLayout.setTitle("Work Order Detail");
    collapsingToolbarLayout.setExpandedTitleColor(Color.parseColor("#ffffff"));
    collapsingToolbarLayout.setCollapsedTitleTextColor(Color.parseColor("#ffffff"));
    collapsingToolbarLayout.setExpandedTitleGravity(Gravity.CENTER | Gravity.BOTTOM);
  }


  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == android.R.id.home) {
      onBackPressed();  return true;
    }

    return super.onOptionsItemSelected(item);
  }
}

1 个答案:

答案 0 :(得分:0)

谢谢大家,我发现了问题,但不确定为什么会这样。我将CollapsingToolbarLayout的背景移动到子LinearLayout,现在差距消失了。