【问题标题】:Android Button layout in GridLayoutGridLayout 中的 Android 按钮布局
【发布时间】:2014-12-09 07:24:10
【问题描述】:

我有一些问题。我想使用 GridLayout 制作 android 布局资源文件。我尝试了很多,但没有我需要的结果。我想使用 GridLayout 来制作它。

看看我的xml布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:background="@drawable/how_we_perform_background"
              android:layout_height="match_parent">
    <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="45sp"
            android:gravity="center"
            android:text="How are We performing?"/>
    <GridLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:numColumns="5">
        <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/selector_smile1"
                android:layout_column="1"
                android:layout_row="1"/>
        <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/selector_smile2"
                android:layout_column="2"
                android:layout_row="1"/>
        <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/selector_smile3"
                android:layout_column="3"
                android:layout_row="1"/>
        <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/selector_smile4"
                android:layout_column="4"
                android:layout_row="1"/>
        <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/selector_smile5"
                android:layout_column="5"
                android:layout_row="1"/>

        <ImageView
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/under_smile_image"
                android:layout_column="1"
                android:layout_row="2"/>
        <ImageView
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/under_smile_image"
                android:layout_column="2"
                android:layout_row="2"/>
        <ImageView
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/under_smile_image"
                android:layout_column="3"
                android:layout_row="2"/>
        <ImageView
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/under_smile_image"
                android:layout_column="4"
                android:layout_row="2"/>
        <ImageView
                android:layout_gravity="center"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/under_smile_image"
                android:layout_column="5"
                android:layout_row="2"/>
    </GridLayout>
</LinearLayout>

在这里你可以看到所有的笑容都没有出现在手机显示屏上。我做错了什么? 我还需要那个按钮不要缩放我放入背景的图像。

【问题讨论】:

    标签: android xml android-layout intellij-idea grid-layout


    【解决方案1】:

    将您的网格视图更改为 match_parent

     <GridLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:numColumns="5">
    

    实际上,我会考虑将 ImageView 设置为固定大小,以便它们都适合屏幕。

    【讨论】:

      猜你喜欢
      • 2011-12-17
      • 1970-01-01
      • 2015-11-22
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多