2016-11-16 2 views
4

私の制約のレイアウトのバージョンは1.0.0-alpha8です。私は私のレイアウトのツールバーが含まれている後、私のツールバーのためのコードAndroidの制約のレイアウトの変な動作

ここenter image description here

下の画像のように、ツールバーの左右両側にスペースがあり、ある

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar 
    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="?attr/actionBarSize" 
    android:background="@color/colorPrimary"> 


</android.support.v7.widget.Toolbar> 

レイアウトに次のように追加しました

<include 
    layout="@layout/toolbar_top" 
    android:id="@+id/topPanel" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent"/> 

私はレイアウトファイルのルート要素に追加の埋め込みや余白を使用しませんでした。私は

<include 
    layout="@layout/toolbar_top" 
    android:id="@+id/topPanel" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent"/> 

変更

<include 
    layout="@layout/toolbar_top" 
    android:id="@+id/topPanel" 
    android:layout_height="wrap_content" 
    android:layout_width="368dp"/> 

に、ガイドラインはまた、私はしませんでしたいくつかの付加価値を追加するように、コンパイルまたは私のコードが自動的に変更プログラムをビルドする場合

もうスタンジェ事があります例えば、layout_editor_absoluteXが自動的に追加されます。

<android.support.constraint.Guideline 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/guideline1" 
    android:orientation="vertical" 
    app:layout_constraintGuide_percent="0.15" 
    tools:layout_editor_absoluteX="58dp"/> 
+0

ターゲットSDK&どのテーマを使用していますか? –

+0

@AnkitaShah targetSdkVersion 24テーマはTheme.AppCompat.Light.NoActionBar –

+0

これを試してみてください 'ツールバーparent =(ツールバー)customView.getParent(); parent.setPadding(0,0,0,0); //タブの場合はそれ以外の場合はタブにスペースを入れます parent.setContentInsetsAbsolute(0,0); ' またはこれをチェックします http://stackoverflow.com/a/28086802/6005977 –

答えて

13

まず、あなたが今ConstraintLayoutベータ4

に更新する必要があり、あなたが持っている根本的な問題は、ツールバー上のmatch_parentを使用していることである - これはConstraintLayoutでサポートされていません。あなたは追加する必要があります。

app:layout_constraintLeft_toLeftOf="parent" 
app:layout_constraintRight_toRightOf="parent" 

とmatch_parentの代わりに0dpを使用する:あなたがコンポーネント上で右クリックをして、そしてimage

を選ぶことにより、容易にそれらの属性を作成することができます

<include 
    layout="@layout/toolbar_top" 
    android:id="@+id/topPanel" 
    android:layout_height="wrap_content" 
    android:layout_width="0dp" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent"/> 

注意をAndroid Studio 2.2では、制約を作成するためにキーを保持する必要があり、Android Studio 2.3ではデフォルトで制約が作成されます。

関連する問題