适合屏幕的gridview元素

时间:2018-01-21 11:27:30

标签: android gridview layout screen-size

我正在实现一个Android应用程序,我希望显示类似下面的图片,在gridview的每个方格内都有imageview和textview,但我无法让所有项目适合整个屏幕。我有一个有限数量的项目要显示,我只是想让它们适合任何屏幕大小的任何屏幕尺寸而不计算尺寸和这个。你能帮助我吗??感谢。

introducir la descripción de la imagen aquí

main.xml中:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rafad.betasentit.MainActivity">

<GridView
    android:id="@+id/appsGridView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorAccent"
    android:numColumns="2">
</GridView>
</FrameLayout>

item.xml:

    <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:padding="10dp">

<TextView
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_weight="1"
    android:padding="5dp"
    android:background="@color/colorPrimary"/>
<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

0 个答案:

没有答案