【问题标题】:How to design this Grid view xml page?如何设计这个 Grid view xml 页面?
【发布时间】:2017-08-02 10:11:10
【问题描述】:

我想设计这种类型的xml页面。我尝试了很多代码。每次都有新的问题出现。我需要固定底部导航栏。在网格视图中,我想要 android:numColums=3android:verticalSpacingandroid:horizontalSpacing 相同(看起来像 instagram 个人资料视图网格图像)。

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"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   tools:context=".MainSettingClass">

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="175dp"
    android:background="#dadada"
    android:gravity="center"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/profile_image"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/com_facebook_button_background"/>

    <TextView
        android:id="@+id/amsc_txt_fbusername"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="TextView"
        android:layout_marginTop="2dp" />

   </LinearLayout>

  <GridView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/grid_test"
    android:verticalSpacing="2dp"
    android:horizontalSpacing="2dp"
    android:background="#FFFFFF"
    android:stretchMode="columnWidth"
    android:columnWidth="85dp"
    android:numColumns="3"/>

  <android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_gallery"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="#ffffff"
    app:menu="@menu/bottom_navigation_gallery"/>

 </FrameLayout>

【问题讨论】:

  • 你做了什么??
  • 我尝试了很多代码...你的代码在哪里?
  • 展示您为实现相同目标所做的努力?
  • 向我们展示您尝试过的任何代码
  • 等我把代码贴出来

标签: java android xml android-layout android-gridview


【解决方案1】:

根据您的设计,上述 2 个组件需要 scrollview,并且您的 BottomNavigationView 已修复(不可移动)。

在您的代码中,您首先没有使用滚动视图,其次我不确定您为什么使用框架布局!

这是我的代码,完全符合您给定的设计,如果您有任何疑问,请试试这个! :)

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       android:layout_above="@+id/bottom_gallery">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/rel_titleHolder"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#dadada"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/profile_image"
                    android:layout_width="100dp"
                    android:layout_height="100dp"
                    android:src="@mipmap/ic_launcher" />

                <TextView
                    android:id="@+id/amsc_txt_fbusername"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="2dp"
                    android:gravity="center"
                    android:text="TextView" />

            </LinearLayout>

            <GridView
                android:id="@+id/grid_test"
                android:layout_width="match_parent"
                android:layout_height="400dp"
                android:columnWidth="85dp"
                android:horizontalSpacing="2dp"
                android:numColumns="3"/>
        </LinearLayout>

    </ScrollView>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottom_gallery"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

【讨论】:

  • 为什么 OP 应该“试试这个”? 好的答案将始终解释所做的事情以及为什么以这种方式完成,不仅适用于 OP,而且适用于 SO 的未来访问者。
  • @bub 感谢您的指导,我会确保这一点.. :) P.S 检查我已经做到了! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多