LinearLayout only show first item

前端 未结 3 990
Happy的楠姐
Happy的楠姐 2021-01-29 09:24

I got problem with LinearLayout, it only shows the first child. I found a solution but i not work.
Here my xml:



        
相关标签:
3条回答
  • 2021-01-29 09:37

    You have defined ImageView's width as MATCH_PARENT so it will take the whole of it's parent and while the parent is HORIZONTAL then the second view will never shown. this may help you

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

    0 讨论(0)
  • 2021-01-29 09:39

    you can try this using weight attribute in image and button

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

    0 讨论(0)
  • 2021-01-29 09:46

    I think you have to set orientation vertical to linear layout like below

    <?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>
    
    0 讨论(0)
提交回复
热议问题