Why doesn't animateLayoutChanges raise a flag on API < 11 - android

I have always used separate layout folders to support features available in newer API versions. One of these features is layout transition using animateLayoutChanges. For this, I create folders layout and layout-v11 and their landscape counterparts.
Today, I found out that having animateLayoutChanges in xml does not raise a flag on API versions < 11. Why is this? Testing on API 8, layout animations were not present, but the app didn't crash either.
Does this mean that I don't have to create separate layout folders (and separate xml files) to support this feature?
To make things clear, here's an example of what I am doing:
res/layout/activity.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llMainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/tvMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Example"
android:textColor="#color/some_color"
android:textSize="#dimen/text_size_message" />
....
....
</LinearLayout>
res/layout-v11/activity.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llMainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:animateLayoutChanges="true" > <<<<<<<<<<<<====================
<TextView
android:id="#+id/tvMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Example"
android:textColor="#color/some_color"
android:textSize="#dimen/text_size_message" />
....
....
</LinearLayout>

Related

How to make an Android view containing an embedded RecyclerView to scroll as a single piece?

I have this piece of layout or Android which is problematic:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="#+id/influencerMainPhotoImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>
<android.support.v7.widget.RecyclerView
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/photos_list"
android:name="com.company.android.InfluencerFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
app:layoutManager="LinearLayoutManager"
tools:context="com.company.android.InfluencerFragment"
tools:listitem="#layout/fragment_photo"/>
</LinearLayout>
The problem is that the embedded RecyclerView is doing nested scrolling (ie. it scrolls within itself) - I don't want this.
I'd like to the entire screen to scroll as a single piece.
I tried to set "view.setNestedScrollingEnabled(false);" (on the LinearLayout view) but it says it works only for API 21 and above. My project is set to min API 15.
What can I do to make the entire screen scroll as a single piece?
You can replace View with ViewCompat(v4 compat lib):
https://developer.android.com/reference/android/support/v4/view/ViewCompat.html
where you have the setNestedScrollingEnabled(boolean); method.

Android constraint layout strange behavior

The version of my constraint layout is 1.0.0-alpha8 . After I have included a toolbar in my layout , there is space in both left and right side of the toolbar, like the image below
Here is the code for my toolbar
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary">
</android.support.v7.widget.Toolbar>
Which I have included in my layout in following way
<include
layout="#layout/toolbar_top"
android:id="#+id/topPanel"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
I didn't used any additional padding or margin in my root element of the layout file .
Another stange thing is if I compile or build the program my code automatically changed, like
<include
layout="#layout/toolbar_top"
android:id="#+id/topPanel"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
Change to
<include
layout="#layout/toolbar_top"
android:id="#+id/topPanel"
android:layout_height="wrap_content"
android:layout_width="368dp"/>
And the guideline also add some additional value which I didn't write, like layout_editor_absoluteX automatically added .
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline1"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.15"
tools:layout_editor_absoluteX="58dp"/>
First, you should update to ConstraintLayout beta 4.
Now, the root problem you have is that you are using match_parent on the toolbar -- this isn't supported by ConstraintLayout. You need to add:
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
and use 0dp instead of match_parent:
<include
layout="#layout/toolbar_top"
android:id="#+id/topPanel"
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
Note that you can create those attributes easily by doing right-click on the component, and picking
On Android Studio 2.2 you need to hold the key to create the constraints, on Android Studio 2.3 it creates the constraints by default.

Unexpected namespace "map" - Android Google Maps API

Here's the entirity of my XML file. The imporant part is the map fragment at the end that gives me this error: "Unexpected namespace prefix found for tag fragment" It doesn't seem to impact the code but I'm curious if anyone knows what's up. I've seen posts saying it's a Lint issue or an Eclipse problem but I'm using the latest version of Android Studio.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:background="#FFFFFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/button_lakeside_webview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lakeside"/>
<Button
android:id="#+id/button_spinner_webview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Spinner"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
android:id="#+id/colored_bar"
android:layout_width="48dp"
android:layout_height="3dp"
android:background="" />
</LinearLayout>
<!-- Unsure why it complains about the map namespace, the below code is recommended by Google -->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraBearing="0"
map:cameraTilt="30"
map:cameraZoom="16"
map:mapType="normal"
map:uiCompass="false"
map:uiRotateGestures="false"
map:uiScrollGestures="false"
map:uiTiltGestures="false"
map:uiZoomControls="false"
map:uiZoomGestures="false"/>
</LinearLayout>
As you say there is a known bug in the Android Lint. There are a couple of issues filed:
Issue 5002: Bug: Options can't be set on MapFragments included in other layouts
Issue 159039: Custom XML attributes doesn't work on tag in layout XMLs
Issue 53283: Library project namespace only working on root element
The last one updated on Jul 14 2016 states that "Please try again on a newer version of Android Studio (2.2 or greater). If the issue still occurs file a new bug."
As a workaround you can add this property to the fragment to ignore the error (I have tested it and the map:properties work as expected):
tools:ignore="MissingPrefix"

Android tablet in Emulator is not picking up the right layout

I am new to Android and trying to learn how to use the multiple layout folders to specify different layouts for different sized devices.
I have tried a few different things, but nothing seems to work to get my emulated tablet to use the larger layout.
My layout directory structure is:
layout
layout-large
layout-sw600dp
layout-xlarge
The main.xml in "layout" is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<SearchView android:id="#+id/searchView"
android:iconifiedByDefault="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#+id/EarthquakeFragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
The main.xml in the other three folders is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<SearchView android:id="#+id/searchView"
android:iconifiedByDefault="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFF"/>
<fragment android:name="com.paad.earthquake.EarthquakeListFragment"
android:id="#+id/EarthquakeListFragment"
android:layout_width="360dp"
android:layout_height="fill_parent"
/>
<fragment android:name="com.paad.earthquake.EarthquakeMapFragment"
android:id="#+id/EarthquakeMapFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
The emulator setup is trying to emulate the Google Nexus 7:
Target: Google APIs (API level 16)
Skin: WXGA800-7in
SD Card: 16M
I'm using all of the other options that come with the skin, plus hw.keyboard=yes and hw.ramSize=512
Does anyone have any idea why this isn't working?
Thank you for your help!
if you are using a 10" tablet and android 3.2 or above, you should have layout-sw720dp folder to have your layout file

Accessing Android views on nested layouts

I have trouble accessing Views from a layout that is included in another layout.
Please take a look at this picture:
http://dl.dropbox.com/u/3473245/layout_includes.png
How do I access the 4 text views programmatically?
Its probably something really simple that I'm missing.
Thank you very much!
You can do as follows:
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include android:id="#+id/item_base_lang" layout="#layout/dictionary_list_item" />
<include android:id="#+id/item_learn_lang" layout="#layout/dictionary_list_item" />
</LinearLayout>
dictionary_list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/dictionary_list_item_text_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/dictionary_list_item_text_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
To set the text programmatically:
((TextView)findViewById(R.id.item_base_lang).findViewById(R.id.dictionary_list_item_text_header)).setText("item_base_lang_header");
((TextView)findViewById(R.id.item_base_lang).findViewById(R.id.dictionary_list_item_text_content)).setText("item_base_lang_content");
((TextView)findViewById(R.id.item_learn_lang).findViewById(R.id.dictionary_list_item_text_header)).setText("item_learn_lang_header");
((TextView)findViewById(R.id.item_learn_lang).findViewById(R.id.dictionary_list_item_text_content)).setText("item_learn_lang_content");
This Android wiki page shows how to use reusable UI components with XML layouts, but it doesn't show how to access nested reusable components from code.
Although it is fairly straightforward, it might be not so clear for those who are pretty new to Android Views.
The following two lines should help you get the languageHeader of both includes. You can do the same for languageText
findViewByid(R.id.activityBaseLangView).findViewById(R.id.languageHeader)
findViewByid(R.id.activityLearnLangView).findViewById(R.id.languageHeader)

Categories

Resources