简体   繁体   English

android GridLayout问题

[英]Problems with android GridLayout

I have two questions about my GridLayout. 我对GridLayout有两个问题。

  1. Why does the layout extand past the phone when I have said to fill parent, and parent is set to match parent? 当我说要填充父级并且将父级设置为与父级匹配时,为什么布局会扩展到电话之外?
  2. Why is the third textview (the one that says "Date") getting mumped down? 为什么第三个textview(说“ Date”的那个)被压低了? There is a big space between the one that says Reserve and the one that says date. 说储备金的日期和说日期的日期之间有很大的距离。

Thanks! 谢谢!

在此处输入图片说明

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/GridLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:columnCount="2"
    android:rowCount="4"
    tools:context=".GridLayoutActivity" >

    <ImageView
        android:id="@+id/imgCabin1"
        android:layout_column="0"
        android:layout_row="0"
        android:layout_rowSpan="3"
        android:layout_height="248dp"
        android:scaleType="fitCenter"
        android:layout_width="200dp"
        android:src="@drawable/sky_beach" 
        android:background="#222222"/>

    <TextView
        android:id="@+id/txtCabint1Title"
        android:layout_width="fill_parent"
        android:layout_height="72sp"
        android:layout_column="1"
        android:layout_row="0"
        android:padding="10sp"
        android:text="Sky Beach"
        android:textSize="48sp" />

    <TextView
        android:id="@+id/txtCabinDesc"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_gravity="left"
        android:layout_row="1"
        android:maxLines="5"
        android:padding="10sp"
        android:singleLine="false"
        android:text="Dog friendly vacation rental cabin on a scenic mountain river"
        android:textSize="24sp" />

    <TextView
        android:id="@+id/btnCabin1Reserve"
        android:layout_width="fill_parent"
        android:layout_height="60sp"
        android:background="#888888"
        android:gravity="left"
        android:layout_column="1"
        android:layout_row="2"
        android:text="Reserve"
        android:textSize="36sp" 
        android:padding="10sp"  />

    <TextView
        android:id="@+id/txtCabinDesc"
        android:layout_width="fill_parent"
        android:layout_height="60sp"
        android:layout_gravity="top"
        android:layout_column="1"
        android:layout_row="3"
        android:text="Date: "
        android:textSize="36sp" 
        android:padding="10sp"  />


</GridLayout>

Instead of using a grid view why are you not using relative layout and set your layout relatively.Your second problem is because your are setting your grid row one after another,hence after setting the imageview it sets your textview txtCabinDesc..Try this following code snippet i have tried. 而不是使用网格视图,为什么不使用相对布局并相对地设置布局。您的第二个问题是因为要依次设置网格行,因此在设置了imageview之后,它将设置textview txtCabinDesc。请尝试以下代码我尝试过的片段。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/GridLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="2"
android:rowCount="4" >

<ImageView
    android:id="@+id/imgCabin1"
    android:layout_column="0"
    android:layout_row="0"
    android:layout_rowSpan="3"
    android:layout_height="248dp"
    android:scaleType="fitCenter"
    android:layout_width="200dp"
    android:src="@drawable/ic_launcher" 
    android:background="#222222"/>

<TextView
    android:id="@+id/txtCabint1Title"
    android:layout_width="match_parent"
    android:layout_toRightOf="@id/imgCabin1"
    android:layout_height="72sp"
    android:layout_column="1"
    android:layout_row="0"
    android:padding="10sp"
    android:text="Sky Beach"
    android:textSize="48sp" />

<TextView
    android:id="@+id/txtCabinDesc"
    android:layout_width="match_parent"
    android:layout_toRightOf="@id/imgCabin1"
    android:layout_below="@id/txtCabint1Title"
    android:layout_height="wrap_content"
    android:layout_column="1"
    android:layout_gravity="left"
    android:layout_row="1"
    android:maxLines="5"
    android:padding="10sp"
    android:singleLine="false"
    android:text="Dog friendly vacation rental cabin on a scenic mountain river"
    android:textSize="24sp" />

<TextView
    android:id="@+id/btnCabin1Reserve"
    android:layout_width="match_parent"
    android:layout_toRightOf="@id/imgCabin1"
    android:layout_below="@id/txtCabinDesc"
    android:layout_height="60sp"
    android:background="#888888"
    android:gravity="left"
    android:layout_column="1"
    android:layout_row="2"
    android:text="Reserve"
    android:textSize="36sp" 
    android:padding="10sp"  />

<TextView
    android:id="@+id/txtCabinDesc1"
    android:layout_width="match_parent"
    android:layout_toRightOf="@id/imgCabin1"
    android:layout_below="@id/btnCabin1Reserve"
    android:layout_height="60sp"
    android:layout_gravity="top"
    android:layout_column="1"
    android:layout_row="3"
    android:text="Date: "
    android:textSize="36sp" 
    android:padding="10sp"  />

Also change your id of the last textView because it clashes with your id of description textView. 还要更改您最后一个textView的ID,因为它与您描述textView的ID冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM