HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

First attempt at designing a 'ProfileActivity'

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
profileactivityfirstdesigningattempt

Problem

I designed this layout in Balsamiq for my ProfileActivityand I tried to replicate it. The screen on the left fits the correct proportions, whereas the screen on the right has a stretched out view of all the content in the activity.

Am I overusing RelativeLayouts? Is there a much easier way to make this? How can I make this layout better for a horizontal orientation?


    

        

            

            

                

                
            

        

        

            

                

                    

                    
                

                

                    

                    

                

            

        

        

            
        

        

            
        

        

            
        

        

            
        

        

            
        

        

            
        

        

            
        

        

            
        

        

            
        

        

            
        

        

            
        

        

            
        
    

Solution

Overusing RelativeLayout

Yes, you're overusing it a bit:

-
Many times you wrap a single view inside RelativeLayout. Try to remove those wrappers.

-
There seem to be an unnecessary layer of RelativeLayout around the box with POSTS and FRIENDS.

However, given that your layout is simple, this shouldn't cause performance issues. The only issue I see with this is aesthetic.

Don't Repeat Yourself

There's a lot of repetition in your text and image elements. It would be good to extract these to styles. For example, create res/values/styles.xml like this:


    
        wrap_content
        wrap_content
    
    
        ?android:attr/textAppearanceMedium
    
    
        ?android:attr/textAppearanceSmall
    


And then in your layout you could simplify some items like this:



These are just examples, for the text items in your POSTS / FRIENDS boxes. You could apply the same technique everywhere. This will help even more when you have many layout files and want to change something uniformly in all of them.

Avoid fixed dimensions

You probably already know this, but it's not good practice to use concrete values for width and height. Avoid them as much as possible. For example in your horizontal rule element, setting the width to 300dip seems really unnecessary. It would be better to let it expand to the possible width, minus some padding.

Code Snippets

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="box_item">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
    </style>
    <style name="box_count" parent="box_item">
        <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
    </style>
    <style name="box_text" parent="box_item">
        <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
    </style>
</resources>
<TextView
    android:id="@+id/num_posts_number_text_view"
    android:layout_marginBottom="15dp"
    style="@style/box_count"
    android:text="10" />

<TextView
    android:id="@+id/num_posts_text_view"
    android:layout_below="@+id/num_posts_number_text_view"
    android:layout_marginTop="15dp"
    style="@style/box_text"
    android:text="@string/posts_uppercase" />

Context

StackExchange Code Review Q#49903, answer score: 4

Revisions (0)

No revisions yet.