【问题标题】:Grid view overlapping other views android网格视图重叠其他视图android
【发布时间】:2013-02-05 14:31:07
【问题描述】:

我需要一个按钮、一个网格视图和一个按钮,垂直排列。我可以看到 Button 和 GridView 但看不到在网格视图之后声明的按钮。为什么?网格视图声明下方的任何视图都会发生这种情况。

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

【问题讨论】:

    标签: android button android-linearlayout android-gridview overlapping


    【解决方案1】:

    由于您采用垂直方向的 LinearLayout,因此将 wrap_content 指定为 GridView 的高度。

    现在,如果您想要屏幕下方的最后一个按钮,请在 GridView 中包含 android:layout_weight="1"。

    【讨论】:

    • 谢谢,它成功了!不敢相信我错过了宽度值 :) 请你看看这个。我想你也许能帮助我。 stackoverflow.com/questions/14702941/…
    • 我现在在网格视图上方有一些其他视图。当我将网格视图的可见性从“消失”更改为“可见”时,它会干扰上面的视图(其中一些视图会消失)。我尝试为所有视图分配权重,但这似乎没有帮助。
    【解决方案2】:

    试试这个

      <RelativeLayout 
       android:layout_width="match_parent"
       android:layout_height="match_parent">
     <Button 
         android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button1"/>
    
     <Button 
        android:id="@+id/button2"  
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Button1"/>
    

    【讨论】:

      【解决方案3】:

      由于您已将 gridview 的高度声明为 match_parent,如果它找不到足够的屏幕空间来显示它,它应该与下面声明的视图重叠。 您应该尝试在gridview 下方声明的视图上调用bringtoFront() 方法。 在我看来,另一件事是尽可能尝试 relativeLayout 并将 android:layout_above 和 android:layout_below 与 gridview 一起使用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多