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" />
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.
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" />
Related
Hy,
When using views and atributtes like the next ones configuring an android layout:
<ImageView
android:src="#android:drawable/ic_partial_secure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="#+id/imageView" />
The number of views and values of these atributtes depend on the api level you are working on?
If it does, how can I know I am not using an atributte or a view that will not be present on an Android device with an api which not contains this atributte?
Thanks
Yes, there are some attributes that require a min API, take a look at this:
android:actionBarStyle requires API level 11
if it does and your min API level (in your build.gradle) is too low then android will tell you.
I am working on an Android Library, which makes buttons of different shapes. The Button's XML looks like this:
<com.singh.daman.mybutton.ShapedButton
android:id="#+id/round"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:fill_color="#color/colorPrimaryDark"
app:button_type="round_rectangle"
app:stroke_color="#color/colorAccent"
app:stroke_width="12sp"
app:text="Round Rectangle"
app:text_size="16sp"
app:text_color="#ffff"
android:layout_gravity="center"
android:background="#null" />
In which attribute app:button_type="round_rectangle" have different values like rectangle, star, circle and round rectangle.
The type round_rectangle is supported by only Lollipop and Above android versions.
So, When the library user sets button_type to round_rectangle and the app minimum android version is less than Lollipop, I want to show an error that it is only supported by api 21 and above, How can I do that?
You need a custom lint rule. I've never done this, but there are writeups from Google on the topic.
http://tools.android.com/tips/lint-custom-rules
I'm trying to follow a tutorial that suppose to show how to add a floating button and in the tutorial it says to add the attribute android:elevation to the buttons xml like this:
<ImageButton
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/editButton"
android:layout_gravity="center|right"
android:clickable="false"
android:background="#drawable/edit_grey"
android:layout_marginRight="1dp"
android:elevation="#dimen/elevation_low"/>
but it dosen't recognize that attribute...i believe it has something to do with my project target or sdk...can somebody help me?
To use android:elevation, just as with any other Android 5.0 API, you must compile against Android 5.0 (API 21). This does not mean you have to change your target SDK level or minimum SDK level.
Note: your XML file may still give a warning that android:elevation only works on Android 5.0 or higher. This warning just serves to tell you that previous versions of Android will not have an elevation shadow on the floating action button. However, that does not cause an error - previous versions of Android will ignore XML attributes they do not understand.
The Elevation attribute is pretty new. It defines the lift of the view it is applied to. It is used for the Material Design in the newest Android Versions.
Material Design
You can use it on API Level 21, I guess your targeted Level is lower than this.
If you just want to achieve some shadowing you can use this:
Shadow Drawables for Views
Or you can use the SupportLibrary with CardViews or something like that, they support elevation from API Level 7:
[How-to] Use the v21 Support Libs on Older Versions & Target L While Remaining Backwards-Compatible
Hope this helps.
I recently downloaded a new ADT. Every time after saving my projects ,it shows the following XML error. But the same goes away when I clean it. Is there a permanent solution for the same.
Thanks in advance.
<TextView
android:id="#+id/selectquantityprompt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="50dip"
android:layout_marginTop="2dip"
android:text="Select Quantity"
android:textSize="20sp"
android:textColor="#33b5e5"
android:paddingLeft="25dp" //error at this line
android:paddingTop="5dp"
android:paddingBottom="5dp"
/>
Multiple annotations found at this line:
- Consider adding android:paddingStart="25dp" to better support right-to-left layouts
- When you define %1$s you should probably also define %2$s for right-to-left
android:paddingStart is newly introduced tag in android 4.2 onwards.
Now RTL means right-to-left layouts which are used in RTL languages like arabic.
So while developing layout you can add same value to paddingStart as padding left. So that when android render RTL layout it will consider paddingStart.
If you are targeting your app to Android 4.2 (the app's
targetSdkVersion or minSdkVersion is 17 or higher), then you should
use “start” and “end” instead of “left” and “right”. For example,
android:paddingLeft should become android:paddingStart.
If you want your app to work with versions earlier than Android 4.2
(the app's targetSdkVersion or minSdkVersion is 16 or less), then you
should add “start” and end” in addition to “left” and “right”. For
example, you’d use both android:paddingLeft and android:paddingStart.
Ref Links: RTL Layout Support
Developer Blog: Native RTL support in Android 4.2
If you want to change the severity of that error go to "Lint Error Checking" at Preferences and change "RtlSymmetry" to "Warning" instead "Error".
Just add android:paddingRight="0dp" along with android:paddingLeft="25dp", error will disappear.
Answer from sreenu solved my issue. But if you target higher APIs you should also add paddingEnd, as in the following example:
android:paddingLeft="25dp"
android:paddingStart="25dp"
android:paddingRight="0dp"
android:paddingEnd="0dp"
Here is my code :
<TextView
android:id="#+id/text_view_title"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_margin="5dp"
android:ellipsize="end"
android:maxLines="2"
android:textSize="#dimen/text_size_small" />
In Android version 2.3.2, text is not showing in two lines, while in higher version device the text is showing in 2 lines. Also when I remove the tag ellipsize then text will be shown in 2 lines. How can I solve this issue?
Remove the ellipsize tag. If you really want it for higher versions, add it programatically when you inflate the layout for android versions above 2.3.
Alternatively, use different layouts for 2.3 and before vs 3.0 and later. But that's more likely to lead to maintenance bugs. If this is the only difference I wouldn't go that route.