按钮的宽度不匹配父的Andr​​oid [英] Button width does not match parent android

查看:124
本文介绍了按钮的宽度不匹配父的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下XML:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
    <TextView
    android:id="@+id/text_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal|center_vertical"
    android:layout_marginTop="20dip"
    android:text="Fragment1"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textSize="30dip" />

    <Button 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button1"/>


 <GridView 
      android:id="@+id/gridview"
      android:layout_width="wrap_content" 
      android:layout_height="match_parent"overla
      android:columnWidth="90dp"
      android:numColumns="auto_fit"
      android:verticalSpacing="10dp"
      android:horizontalSpacing="10dp"
      android:stretchMode="columnWidth"
      android:gravity="center"/>                            

        <Button 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button1"/>
 </LinearLayout>

Button1的用于切换网格视图的可见性。但是,当网格视图是不可见的,该按钮不填充屏幕。他们占据了半个屏幕。当电网视图可见虽然,按键占据了所有的画面,因为我希望他们。我一直无法理解这种奇怪的行为。

The button1 is used to toggle the visibility of the grid view. But, when the grid view is not visible, the buttons don't fill the screen. They occupy half the screen. When the grid view is visible though, the buttons occupy all of the screen as I want them to. I haven't been able to understand this strange behaviour.

推荐答案

尝试改变的宽度线性布局来的 match_parent

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

这篇关于按钮的宽度不匹配父的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆