草庐IT

在所有移动屏幕尺寸上支持设计两个卡视图和瓷砖网格

程序员大本营 2025-04-23 原文

我需要设计下面的视图。

解释 :

前两个视图是卡片视图。顶部将包含下面的图表是4个瓷砖,该图像在其底部具有图像和文本

问题 :

我能够获得这样的设计,但并不适合所有手机和屏幕类型。我怎样才能解决这个问题 ?

代码:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:card_view="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#eaeaea"    app:layout_behavior="@string/appbar_scrolling_view_behavior"    tools:context=".activity.MainActivity"    tools:showIn="@layout/app_bar_main">    <FrameLayout        android:id="@+id/content_frame"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:layout_alignParentBottom="true"        android:layout_alignParentStart="true">        <LinearLayout android:id="@+id/reportView"            android:layout_width="match_parent"            android:layout_height="268dp"            android:layout_marginLeft="6dp"            android:layout_marginRight="6dp"            android:layout_marginTop="6dp"            android:orientation="horizontal"            android:weightSum="1.0">            <android.support.v7.widget.CardView                android:layout_width="match_parent"                android:layout_height="match_parent"                card_view:cardElevation="3dp"                card_view:cardUseCompatPadding="true">                <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"                    android:layout_width="match_parent"                    android:layout_height="match_parent"                    android:orientation="vertical"                    android:weightSum="1.0">                    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"                        android:layout_width="match_parent"                        android:layout_height="wrap_content"                        android:orientation="vertical"                        android:layout_weight="0.5"                        android:layout_marginTop="5dp"                        android:gravity="start">                        <TextView                            android:layout_width="match_parent"                            android:layout_height="match_parent"                            android:layout_gravity="start"                            android:text="Inventory / Missing Report"                            android:textSize="20dp"                            android:textAlignment="center"                            android:textColor="#4e28d8" />                    </LinearLayout>                    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"                        android:layout_width="match_parent"                        android:layout_height="202dp"                        android:gravity="bottom"                        android:orientation="vertical">                        <com.github.mikephil.charting.charts.PieChart                            android:id="@+id/chart"                            android:layout_width="match_parent"                            android:layout_height="177dp" />                    </LinearLayout>                </LinearLayout>            </android.support.v7.widget.CardView>        </LinearLayout>        <android.support.v7.widget.CardView            android:layout_width="match_parent"            android:layout_height="280dp"            android:orientation="horizontal"            android:layout_marginLeft="6dp"            android:layout_marginRight="6dp"            android:layout_gravity="bottom"            android:weightSum="1.0">            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"                android:layout_width="match_parent"                android:layout_height="match_parent"                android:orientation="vertical" >                <LinearLayout                    android:layout_width="match_parent"                    android:layout_height="0dip"                    android:orientation="horizontal"                    android:layout_weight="1" >                    <LinearLayout                        android:layout_height="match_parent"                        android:layout_width="0dip"                        android:layout_weight="1"                        android:orientation="vertical"                        android:padding="16dp"                        android:paddingTop="15dp"                        android:id="@+id/shorcut_scan">                        <ImageView                            android:src="@drawable/ic_scan"                            android:layout_width="70dp"                            android:layout_height="70dp"                            android:layout_gravity="center"                            android:id="@+id/shorcut_scan_image"/>                        <TextView                            android:id="@+id/shorcut_scan_txt"                            android:layout_height="wrap_content"                            android:layout_width="wrap_content"                            android:text="Scan"                            android:layout_gravity="center"/>                    </LinearLayout>                    <LinearLayout                        android:layout_height="match_parent"                        android:layout_width="0dip"                        android:layout_weight="1"                        android:orientation="vertical"                        android:padding="16dp"                        android:paddingTop="15dp"                        android:id="@+id/shorcut_search">                        <ImageView                            android:src="@android:drawable/ic_menu_search"                            android:layout_width="70dp"                            android:layout_height="70dp"                            android:layout_gravity="center"                            android:id="@+id/shorcut_search_image"/>                        <TextView                            android:id="@+id/shorcut_search_txt"                            android:layout_height="wrap_content"                            android:layout_width="wrap_content"                            android:text="Search"                            android:layout_gravity="center"/>                    </LinearLayout>                </LinearLayout>                <LinearLayout                    android:layout_width="match_parent"                    android:layout_height="0dip"                    android:orientation="horizontal"                    android:layout_weight="1" >                    <LinearLayout                        android:layout_height="match_parent"                        android:layout_width="0dip"                        android:layout_weight="1"                        android:orientation="vertical"                        android:padding="16dp"                        android:paddingTop="15dp"                        android:id="@+id/shorcut_assign_tags">                        <ImageView                            android:src="@drawable/ic_assign_tag"                            android:layout_width="70dp"                            android:layout_height="70dp"                            android:layout_gravity="center"                            android:id="@+id/shorcut_assign_tags_image"/>                        <TextView                            android:id="@+id/shorcut_assign_tags_txt"                            android:layout_height="wrap_content"                            android:layout_width="wrap_content"                            android:text="Assign"                            android:layout_gravity="center"/>                    </LinearLayout>                    <LinearLayout                        android:layout_height="match_parent"                        android:layout_width="0dip"                        android:layout_weight="1"                        android:orientation="vertical"                        android:padding="16dp"                        android:paddingTop="15dp"                        android:id="@+id/shorcut_edit_tags">                        <ImageView                            android:src="@drawable/ic_assign_tag"                            android:layout_width="70dp"                            android:layout_height="70dp"                            android:layout_gravity="center"                            android:id="@+id/shorcut_edit_tags_image"/>                        <TextView                            android:id="@+id/shorcut_edit_tags_txt"                            android:layout_height="wrap_content"                            android:layout_width="wrap_content"                            android:text="Edit"                            android:layout_gravity="center"/>                    </LinearLayout>                </LinearLayout>            </LinearLayout>        </android.support.v7.widget.CardView>    </FrameLayout></RelativeLayout>

看答案

尝试这个 :

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:card_view="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#eaeaea"    app:layout_behavior="@string/appbar_scrolling_view_behavior">    <FrameLayout        android:id="@+id/content_frame"        android:layout_width="match_parent"        android:layout_height="match_parent">        <LinearLayout            android:layout_width="match_parent"            android:layout_height="match_parent"            android:orientation="vertical">            <android.support.v7.widget.CardView                android:layout_width="match_parent"                android:layout_height="0dp"                android:layout_marginBottom="20dp"                android:layout_weight="50"                android:paddingBottom="50dp"                card_view:cardElevation="3dp"                card_view:cardUseCompatPadding="true">                <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"                    android:layout_width="match_parent"                    android:layout_height="match_parent"                    android:orientation="vertical">                    <TextView                        android:layout_width="match_parent"                        android:layout_height="0dp"                        android:layout_weight="1.2"                        android:layout_gravity="start"                        android:padding="5dp"                        android:text="Inventory / Missing Report"                        android:textAlignment="center"                        android:textColor="#4e28d8"                        android:textSize="20dp" />                    <com.github.mikephil.charting.charts.PieChart                        android:id="@+id/chart"                        android:layout_width="match_parent"                        android:layout_height="180dp" />                </LinearLayout>            </android.support.v7.widget.CardView>            <android.support.v7.widget.CardView                android:layout_width="match_parent"                android:layout_height="0dp"                android:layout_gravity="bottom"                android:layout_marginLeft="6dp"                android:layout_marginRight="6dp"                android:layout_weight="50"                android:layout_marginBottom="20dp"                android:orientation="horizontal"                android:weightSum="1.0">                <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"                    android:layout_width="match_parent"                    android:layout_height="match_parent"                    android:orientation="vertical">                    <LinearLayout                        android:layout_width="match_parent"                        android:layout_height="0dip"                        android:layout_weight="1"                        android:orientation="horizontal">                        <LinearLayout                            android:id="@+id/shorcut_scan"                            android:layout_width="0dip"                            android:layout_height="match_parent"                            android:layout_weight="1"                            android:orientation="vertical"                            android:padding="16dp"                            android:paddingTop="15dp">                            <ImageView                                android:id="@+id/shorcut_scan_image"                                android:layout_width="70dp"                                android:layout_height="70dp"                                android:layout_gravity="center"                                 />                            <TextView                                android:id="@+id/shorcut_scan_txt"                                android:layout_width="wrap_content"                                android:layout_height="wrap_content"                                android:layout_gravity="center"                                android:text="Scan" />                        </LinearLayout>                        <LinearLayout                            android:id="@+id/shorcut_search"                            android:layout_width="0dip"                            android:layout_height="match_parent"                            android:layout_weight="1"                            android:orientation="vertical"                            android:padding="16dp"                            android:paddingTop="15dp">                            <ImageView                                android:id="@+id/shorcut_search_image"                                android:layout_width="70dp"                                android:layout_height="70dp"                                android:layout_gravity="center"                                android:src="@android:drawable/ic_menu_search" />                            <TextView                                android:id="@+id/shorcut_search_txt"                                android:layout_width="wrap_content"                                android:layout_height="wrap_content"                                android:layout_gravity="center"                                android:text="Search" />                        </LinearLayout>                    </LinearLayout>                    <LinearLayout                        android:layout_width="match_parent"                        android:layout_height="0dip"                        android:layout_weight="1"                        android:orientation="horizontal">                        <LinearLayout                            android:id="@+id/shorcut_assign_tags"                            android:layout_width="0dip"                            android:layout_height="match_parent"                            android:layout_weight="1"                            android:orientation="vertical"                            android:padding="16dp"                            android:paddingTop="15dp">                            <ImageView                                android:id="@+id/shorcut_assign_tags_image"                                android:layout_width="70dp"                                android:layout_height="70dp"                                android:layout_gravity="center"                                />                            <TextView                                android:id="@+id/shorcut_assign_tags_txt"                                android:layout_width="wrap_content"                                android:layout_height="wrap_content"                                android:layout_gravity="center"                                android:text="Assign" />                        </LinearLayout>                        <LinearLayout                            android:id="@+id/shorcut_edit_tags"                            android:layout_width="0dip"                            android:layout_height="match_parent"                            android:layout_weight="1"                            android:orientation="vertical"                            android:padding="16dp"                            android:paddingTop="15dp">                            <ImageView                                android:id="@+id/shorcut_edit_tags_image"                                android:layout_width="70dp"                                android:layout_height="70dp"                                android:layout_gravity="center"                                 />                            <TextView                                android:id="@+id/shorcut_edit_tags_txt"                                android:layout_width="wrap_content"                                android:layout_height="wrap_content"                                android:layout_gravity="center"                                android:text="Edit" />                        </LinearLayout>                    </LinearLayout>                </LinearLayout>            </android.support.v7.widget.CardView>        </LinearLayout>    </FrameLayout></RelativeLayout>

您需要使用线性布局并将重量分配给两个卡布局50-50。

有关在所有移动屏幕尺寸上支持设计两个卡视图和瓷砖网格的更多相关文章

  1. ruby-on-rails - Rails - 子类化模型的设计模式是什么? - 2

    我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co

  2. ruby - 如何以所有可能的方式将字符串拆分为长度最多为 3 的连续子字符串? - 2

    我试图获取一个长度在1到10之间的字符串,并输出将字符串分解为大小为1、2或3的连续子字符串的所有可能方式。例如:输入:123456将整数分割成单个字符,然后继续查找组合。该代码将返回以下所有数组。[1,2,3,4,5,6][12,3,4,5,6][1,23,4,5,6][1,2,34,5,6][1,2,3,45,6][1,2,3,4,56][12,34,5,6][12,3,45,6][12,3,4,56][1,23,45,6][1,2,34,56][1,23,4,56][12,34,56][123,4,5,6][1,234,5,6][1,2,345,6][1,2,3,456][123

  3. ruby - 多次弹出/移动 ruby​​ 数组 - 2

    我的代码目前看起来像这样numbers=[1,2,3,4,5]defpop_threepop=[]3.times{pop有没有办法在一行中完成pop_three方法中的内容?我基本上想做类似numbers.slice(0,3)的事情,但要删除切片中的数组项。嗯...嗯,我想我刚刚意识到我可以试试slice! 最佳答案 是numbers.pop(3)或者numbers.shift(3)如果你想要另一边。 关于ruby-多次弹出/移动ruby​​数组,我们在StackOverflow上找到一

  4. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  5. ruby-on-rails - 使用 rails 4 设计而不更新用户 - 2

    我将应用程序升级到Rails4,一切正常。我可以登录并转到我的编辑页面。也更新了观点。使用标准View时,用户会更新。但是当我添加例如字段:name时,它​​不会在表单中更新。使用devise3.1.1和gem'protected_attributes'我需要在设备或数据库上运行某种更新命令吗?我也搜索过这个地方,找到了许多不同的解决方案,但没有一个会更新我的用户字段。我没有添加任何自定义字段。 最佳答案 如果您想允许额外的参数,您可以在ApplicationController中使用beforefilter,因为Rails4将参数

  6. ruby-on-rails - 跳过状态机方法的所有验证 - 2

    当我的预订模型通过rake任务在状态机上转换时,我试图找出如何跳过对ActiveRecord对象的特定实例的验证。我想在reservation.close时跳过所有验证!叫做。希望调用reservation.close!(:validate=>false)之类的东西。仅供引用,我们正在使用https://github.com/pluginaweek/state_machine用于状态机。这是我的预订模型的示例。classReservation["requested","negotiating","approved"])}state_machine:initial=>'requested

  7. ruby - Nokogiri 剥离所有属性 - 2

    我有这个html标记:我想得到这个:我如何使用Nokogiri做到这一点? 最佳答案 require'nokogiri'doc=Nokogiri::HTML('')您可以通过xpath删除所有属性:doc.xpath('//@*').remove或者,如果您需要做一些更复杂的事情,有时使用以下方法遍历所有元素会更容易:doc.traversedo|node|node.keys.eachdo|attribute|node.deleteattributeendend 关于ruby-Nokog

  8. ruby - 获取模块中定义的所有常量的值 - 2

    我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c

  9. ruby-on-rails - 如何重命名或移动 Rails 的 README_FOR_APP - 2

    当我在我的Rails应用程序根目录中运行rakedoc:app时,API文档是使用/doc/README_FOR_APP作为主页生成的。我想向该文件添加.rdoc扩展名,以便它在GitHub上正确呈现。更好的是,我想将它移动到应用程序根目录(/README.rdoc)。有没有办法通过修改包含的rake/rdoctask任务在我的Rakefile中执行此操作?是否有某个地方可以查找可以修改的主页文件的名称?还是我必须编写一个新的Rake任务?额外的问题:Rails应用程序的两个单独文件/README和/doc/README_FOR_APP背后的逻辑是什么?为什么不只有一个?

  10. ruby - 这两个 Ruby 类初始化定义有什么区别? - 2

    我正在阅读一本关于Ruby的书,作者在编写类初始化定义时使用的形式与他在本书前几节中使用的形式略有不同。它看起来像这样:classTicketattr_accessor:venue,:datedefinitialize(venue,date)self.venue=venueself.date=dateendend在本书的前几节中,它的定义如下:classTicketattr_accessor:venue,:datedefinitialize(venue,date)@venue=venue@date=dateendend在第一个示例中使用setter方法与在第二个示例中使用实例变量之间是

随机推荐