Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Self-Destructing Message Android App Retrieving and Viewing Messages Creating a Custom List Layout for Messages

android:paddingLeft gives an error both in the ImageView and TextView

The error I get is as follows :

Multiple annotations found at this line:

  • When you define paddingLeft you should probably also define paddingRight for right-to-left symmetry

  • Consider adding android:paddingStart="@dimen/activity_horizontal_margin" to better support right-to-left layouts

Edit : Here is the whole xml file

'''xml <?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="wrap_content" >

<ImageView
    android:id="@+id/messageIcon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:paddingLeft = "@dimen/activity_horizontal_margin"
    android:src="@drawable/ic_action_picture" />

<TextView
    android:id="@+id/senderLabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/messageIcon"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:paddingLeft="@dimen/activity_horizontal_margin"
 />

</RelativeLayout> '''

Stone Preston
Stone Preston
42,016 Points

can you post your code

Just posted the code in the edit above ^. The error is at both the android:paddingLeft lines.

2 Answers

Stone Preston
Stone Preston
42,016 Points

is it an error or just a warning?

try adding

android:paddingStart="@dimen/activity_horizontal_margin"

in addition to padding left:

<ImageView
    android:id="@+id/messageIcon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:paddingLeft = "@dimen/activity_horizontal_margin"
    android:paddingStart="@dimen/activity_horizontal_margin"
    android:src="@drawable/ic_action_picture" 
    />

<TextView
    android:id="@+id/senderLabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/messageIcon"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingStart="@dimen/activity_horizontal_margin"
 />

It is an error alright... the same verbage as I mentioned in my question. Actually the error is due to me not adding right-padding... If I add paddingStart, it just gives the same error on that line as well and asks me to add paddingEnd like paddingRight in the former case.

Devanshu, are you sure you posted the entire XML file? If so, it appears that your views are not actually contained within a layout. You need to place them within a LinearLayout or RelativeLayout.

Since your code implies a RelativeLayout (i.e. with the alignParentLeft attribute) I placed it within a RelativeLayout using an empty test project in Android Studio. Here's the code:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/messageIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:paddingLeft = "@dimen/activity_horizontal_margin"
        android:src="@drawable/ic_action_picture" />

    <TextView
        android:id="@+id/senderLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/messageIcon"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        />

</RelativeLayout>

Android Studio didn't flag me with any errors for the above code, and I even hooked it up to a default Activity and ran it successfully without issue. If you're still getting errors using the above code, it must be related to something other than the XML itself.

Hope this helps!

I did select Relative Layout while creating the layout file, however I replaced my layout file by the one created by Ben and now it seems to be working. Might have been a non-reproducible error.