2017-06-08 1 views
-2

J'ai eu un problème avec LinearLayout, il montre seulement le premier enfant. J'ai trouvé un solution mais je ne travaille pas.
Voici mon xml:LinéaireS'il vous plaît montrer le premier élément

<?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> 

ici est le résultat quand je change la position de Button et ImageView

enter image description here

et

enter image description here

+2

Les deux 'View's à l'intérieur de' LinearLayout 'horizontal ont 'layout_width's de' match_parent'. Le second est poussé sur le côté. –

+1

merci pour la réponse, je ne suis pas bon en anglais j'ai été mal compris avec 'horizontal' et' vertical' –

Répondre

2

Je pense que vous devez définir l'orientation verticale disposition linéaire comme ci-dessus

<?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> 
1

Vous avez défini la largeur de ImageView comme MATCH_PARENT donc il prendra l'ensemble de son parent et tandis que le parent est HORIZONTAL alors la deuxième vue ne sera jamais montrée. cela peut vous aider à

<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

vous pouvez essayer cet attribut de poids à l'aide dans l'image et le bouton

<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"/>