一个活动应该有多少次展示?

问题描述:

我知道,在XML中,视图是昂贵的,最好你应该争取尽可能少。但对我来说,我设计我的布局在这样一个,我有点被迫有很多意见的方式,接近80的Eclipse给了我这个警告,所以我删除了一些意见,但我只能做了这么多我的实现需要最低,48次了蝙蝠,而不是包括一些额外的东西。所以我的问题是我是否应该真正找到一个更简单的方法,或者它的罚款。什么是真正应该是最大的实际人数?

I know that in XML, Views are expensive, and ideally you should strive for as little as possible. But in my case, I am designing my layout in a such a way that I am sort of forced to have a lot of Views, close to 80. Eclipse gave me a warning on this, so I deleted some Views, but I can only do so much as my implementation requires minimum, 48 Views off the bat, and not including some extra stuff. So my question is in whether I should really find a simpler way, or if its fine. What is the actual number that really should be maximum?

XML文件

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/top_bar_date_display"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="July 1, 2012"
        android:background="#696969"/>
<ScrollView 
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    >
<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/day_view_floaty_holder"
    android:background="#000000">
    <GridLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnCount="1" >

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >
            <TextView 
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="12\nAM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal"
                android:layout_marginBottom="1dp" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView 
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="1\nAM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>
        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView 
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="2\nAM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView 
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="3\nAM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView 
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="4\nAM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView 
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="5\nAM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView 
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="6\nAM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView 
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="7\nAM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView 
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="8\nAM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView 
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="9\nAM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView 
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="10\nAM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="11\nAM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >
            <TextView
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="12\nPM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="1\nPM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="2\nPM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="3\nPM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="4\nPM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="5\nPM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="6\nPM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="7\nPM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="8\nPM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="9\nPM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="10\nPM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:orientation="vertical"
            android:background="#ffffff"
            android:layout_marginBottom="1dp" >

            <TextView
                android:layout_width="20dp"
                android:layout_height="60dp"
                android:text="11\nPM"
                android:background="#bebebe"
                android:textSize="10dp"
                android:gravity="center_horizontal" />
        </LinearLayout>

    </GridLayout>

    <!-- THIS GRIDLAYOUT IS WHERE THE EVENTS WILL BE PLACED-->
    <GridLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnCount="1" >
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_0"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_1"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_2"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_3"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_4"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_5"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_6"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_7"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_8"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_9"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_10"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_11"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_12"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_13"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_14"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_15"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_16"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_17"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_18"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_19"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_20"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_21"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_22"
            android:orientation="horizontal" ></LinearLayout>
        <LinearLayout 
            android:layout_height="61dp"
            android:layout_width="match_parent"
            android:layout_marginLeft="20dp"
            android:id="@+id/day_view_23"
            android:orientation="horizontal" ></LinearLayout>

    </GridLayout>


</RelativeLayout>
</ScrollView>

我也许应该解释的背后是什么code转换为逻辑。我基本上需要它上面浮起另一个24行的24行的网格布局,以及另一个GridLayout的。我这样做是为了区分什么,我需要浮在第一GridLayout的上方。它的假设是每天查看的日历应用程序。

I should probably explain the logic behind what the code translated to. I essentially needed a GridLayout of 24 rows, as well as another GridLayout of another 24 rows floated above it. I did this to separate what I need to float above the first GridLayout. Its suppose to be for a Day View for a calendar app.

正如我所说的,我会用一个的ListView 来显示数据,以避免弄出这么大的意见。首先,我想创建一个类来重新present您在列表中显示用户事件:

As I said I would use a ListView to show the data to avoid making so much views. First I would create a class to represent the user events that you show in the list:

private static class Event {

        public int startHour;
        public int hours = 1;
        public String name;
        public String date;
        public boolean isEmptyEvent = true;

        public Event(int startHour, int hours, String name, String date,
                boolean isEmptyEvent) {
            this.startHour = startHour; 0 to 23 (the method getStartHour makes this pretty)
            this.hours = hours; // how many this event requires(default 1)
            this.name = name;
            this.date = date;
            this.isEmptyEvent = isEmptyEvent;
        }

        public String getStartHour() {
            // should optimize this method so you don't end up creating String
            // after String(char array?)!
            if (startHour < 10) {
                return "0" + startHour + ":00";
            }
            return String.valueOf(startHour) + ":00";
        }
    }

然后我会在解析事件我有数据对象(我不知道你在数据库中保存什么,所以这仅仅是猜测):

Then I would parse the data I have in Events object(I don't know what you save in the database so this is just guessing):

public SparseArray<Event> getData(String date) {
        // here you get the data from the database and create Events object for
        // those dates
        SparseArray<Event> data = new SparseArray<Event>(); // for efficiency
                // add some random events
        data.put(3, new Event(3, 1, "Breackfast", date, false));// one event at 3 taking 1 hour
        data.put(14, new Event(14, 3, "Lunch", date, false));// one event at 14 taking 3 hour
        data.put(20, new Event(20, 2, "Dinner", date, false));// one event at 20 taking 2 hour
        return data;
    }

然后在适配器我将填补空白项(其中用户还没有任何设置),空活动其余对象,并将其展示给用户。由于code是有点大了,我不会张贴在这里,而不是你可以找到完整的活动+这里布局 HTTPS ://gist.github.com/3370107

Then in the adapter I would fill the rest of the empty entries(where the user didn't yet set anything) with empty Events objects and show it to the user. As the code is a little big I will not post it here , instead you can find the full activity+ layouts here https://gist.github.com/3370107