Amos
Amos

Reputation: 1341

Android Studio - avoid layout warning for different APIs

I have this in res/layout

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/txt"
    android:layout_alignBottom="@+id/txt"
    android:layout_toRightOf="@+id/txt"
    android:text="@string/..."
    android:layout_marginLeft="3dp"
    android:textAppearance="?android:attr/textAppearanceSmall" />

I get warnings that layout_toRightOf should be layout_toEndOf and that layout_marginLeft should be layout_marginStart to better support right to left layouts.

So I made 2 layouts and put the other one inside layout-v17 and changed what it wanted. While layout-v17 is OK now, the warnings on the original layout file are still there, how can I let it know I already handled that?

Upvotes: 0

Views: 5193

Answers (3)

natario
natario

Reputation: 25194

These warning come from Lint, a tool implemented in your SDK, which is checking the whole project looking for potential bugs. Check this and this out.

Here's a list of Lint checks, each of which can be ignored using the tools:ignore= attribuite, as long as you have defined xmlns:tools="http://schemas.android.com/tools" in your root view. Of course this feature should be used only when needed, as lint checks can be useful in preventing bugs.

The attribute related to your issue, which in any case shouldn't be really annoying, is RtlHardcoded.

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="RtlHardcoded" >

    <TextView
        android:text="@string/text"
        android:layout_toRightOf="@+id/txt" />
</RelativeLayout>

Note that you can also disable specific Lint checks from your IDE options for the whole project, but I wouldn't do that. (in Android Studio, Project Settings -> Inspections).

Edit: Note also that this is not ignoring a real issue. I suggested you to do so because I imagined you just being "bothered" by a warning about a situation you already managed. In these cases, tools:ignore can be used to tell Lint "OK, I'm aware of the issue and I already managed it" (most of the cases, Lint is smart enough to notice on its own).

Regarding right-to-left layouts, best way to deal with them is to put both left(right) / start(end) attributes. On API>17, the latter will have priority.

Upvotes: 3

QArea
QArea

Reputation: 4981

Try this

<TextView
android:id="+id/textView1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignBaseline="id/txt" 
android:layout_alignBottom="id/txt" 
android:layout_toRightOf="id/txt" 
android:text="@string/..." 
android:layout_marginLeft="3dp" 
android:textAppearance="?android:attr/textAppearanceSmall" />

or

<TextView
android:id="+id/textView1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignBaseline="txt" 
android:layout_alignBottom="txt" 
android:layout_toRightOf="txt" 
android:text="@string/..." 
android:layout_marginLeft="3dp" 
android:textAppearance="?android:attr/textAppearanceSmall" />

Upvotes: 0

Anthone
Anthone

Reputation: 2290

Put twice layout_toRightOf and layout_toEndOf in the same textview

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toEndOf="@+id/txt"
    android:layout_toRightOf="@+id/txt"
    />

Upvotes: 0

Related Questions