问题描述:

My layout code below, using android:layout_alignStart, was working flawlessly in Eclipse. However, recently I switched to the official Android Studio. When I use the alignStart property there, Android Studio underlines it with a wavy red line and says "To support older versions than API 17(project specifies 9) you should also add android:layout_alignLeft="@+id/textview1".

However, I tried replacing it as recommended by Android Studio, and I do not get the output alignStart was supposed to give! I am trying to place dataView2 to the right of textView2, but it currently lies on top of textView2...

<TextView

android:id="@+id/dataView2"

android:layout_toRightOf="@+id/textView2"

android:layout_alignStart="@+id/dataView1"

android:layout_alignBelow="@+id/dataView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/planet_mass_label" />

网友答案:

Since your original code uses layout_alignStart="@+id/dataView1", the line you should add for pre-API 17 compatibility is

android:layout_alignLeft="@+id/dataView1"

not

android:layout_alignLeft="@+id/textView1"

The final code should be

<TextView 
    android:id="@+id/dataView2"
    android:layout_toRightOf="@+id/textView2"
    android:layout_alignStart="@+id/dataView1"
    android:layout_alignLeft="@+id/dataView1"
    android:layout_alignBelow="@+id/dataView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/planet_mass_label" />
网友答案:

Currently your minSdk is 9, so you're getting that red line which says "To support older versions than API 17(project specifies 9) you should also add android:layout_alignLeft="@+id/textview1".

Refer this link: http://android-developers.blogspot.in/2013/03/native-rtl-support-in-android-42.html

If you want your minSdk to be 9 or less than 17, than you should use both, android:layout_alignLeft="@+id/dataView1"

android:layout_alignStart="@+id/dataView1"

accordingly.

相关阅读:
Top