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 file
<?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>
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.
As I said I would use a
ListViewto 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:Then I would parse the data I have in
Eventsobject(I don’t know what you save in the database so this is just guessing):Then in the adapter I would fill the rest of the empty entries(where the user didn’t yet set anything) with empty
Eventsobjects 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