2017-06-08 14 views
-2

LinearLayoutに問題があり、最初の子のみが表示されます。私はsolutionを見つけましたが、私はうまくいきません。
ここに私のxml:ここLinearLayoutは最初の項目を表示します

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true" 
    tools:context="com.example.hoangdang.diemdanh.QRCode.QRCodeActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/qrcode_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@color/primary_darker" 
      app:popupTheme="@style/AppTheme.PopupOverlay"/> 

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:orientation="horizontal"> 

     <android.support.v7.widget.AppCompatImageView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/qrCode_imageView" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true"/> 

     <android.support.v7.widget.AppCompatButton 
      android:id="@+id/generate_code_button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/generate_code" 
      android:layout_marginRight="@dimen/de_btn_padding" 
      android:layout_marginLeft="@dimen/de_btn_padding"/> 

    </LinearLayout> 

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

iはButtonImageView

enter image description here

enter image description here

+2

水平 'LinearLayout'内の' View'sは、 'match_parent'の' layout_width'を持っています。 2つ目はサイドから押し出されています。 –

+1

レスポンスありがとう、私は英語が上手ではない私は '水平'と '垂直' –

答えて

2

を試すことができます

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/qrcode_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@color/primary_darker" 
     app:popupTheme="@style/AppTheme.PopupOverlay"/> 

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    android:orientation="horizontal"> 

    <android.support.v7.widget.AppCompatImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/qrCode_imageView" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true"/> 

    <android.support.v7.widget.AppCompatButton 
     android:id="@+id/generate_code_button" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/generate_code" 
     android:layout_marginRight="@dimen/de_btn_padding" 
     android:layout_marginLeft="@dimen/de_btn_padding"/> 

</LinearLayout> 

1

の位置を変更するときのようにImageViewのの幅を定義した結果であり、 MATCH_PARENTそれは親の全体をとって、親がHORIZONTALの間は2番目のビューは決して表示されません。これは、あなたがこの使用量の画像内の属性やボタン

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
android:orientation="horizontal"> 

<android.support.v7.widget.AppCompatImageView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/qrCode_imageView" 
    android:layout_weight="1" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true"/> 

<android.support.v7.widget.AppCompatButton 
    android:id="@+id/generate_code_button" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="@string/generate_code" 
    android:layout_marginRight="@dimen/de_btn_padding" 
    android:layout_marginLeft="@dimen/de_btn_padding"/> 

1

役立つかもしれない、私はあなたが垂直の向きを設定することがあると思います上記のような線形レイアウト

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true" 
    tools:context="com.example.hoangdang.diemdanh.QRCode.QRCodeActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/qrcode_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@color/primary_darker" 
      app:popupTheme="@style/AppTheme.PopupOverlay"/> 

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:orientation="vertical"> 

     <android.support.v7.widget.AppCompatImageView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/qrCode_imageView" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true"/> 

     <android.support.v7.widget.AppCompatButton 
      android:id="@+id/generate_code_button" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/generate_code" 
      android:layout_marginRight="@dimen/de_btn_padding" 
      android:layout_marginLeft="@dimen/de_btn_padding"/> 

    </LinearLayout> 

</android.support.design.widget.CoordinatorLayout> 
関連する問題