Android tablet in Emulator is not picking up the right layout - android

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

Related

Change the quality of an ImageView

I'm trying to make a splash screen, I'm doing that with react native, but I'm using android studio to create the style.
First of all, I'm following this video that uses this library.
I have the following code of my splash screen:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/primary"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/launch_screen"
android:scaleType="centerCrop" />
</LinearLayout>
</RelativeLayout>
It looks like this:
As you can see, the quality of the logo is low, and I would like to make it better.
My drawable folder is the following:
Thanks!
It seems that your launch_screen.png file has a small resolution.
Change that file with bigger resolution with better quality.

Android landscape mode looks bad

My user interface looks like that in landscape mode:
But I want to have them in parallel. so the should have width / 2 instead of height/ 2. So how can I change that?
My code looks like that:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/photo"
android:layout_weight="0.5"
android:id="#+id/btnTakePhoto" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/video"
android:layout_weight="0.5"
android:id="#+id/btnRecordVideo"
/>
</LinearLayout>
</FrameLayout>
Thanks in advance for your help!
Add layout-land folder in your res folder in app directory and design xml's with same name in this folder . Android frameworks will detects the mode and will select the layout file defined within layout-land folder .
*remember xml file name in layout and layout-land folder should be same .

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 - merge and include

I want to use switch button in my app. As its API is 11 and switch needs API higher than 14, I decided to use merge and include method but I get this error in values-v14/compound_switch.xml file : Element merge must be declerd. here are my files, what is the problem?
Main layout:
<include layout="#layout/compound_switch" />
layout/compound_switch.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:id="#+id/night_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView20"
android:layout_toLeftOf="#+id/textView20"
android:layout_toStartOf="#+id/textView20"
android:layout_marginRight="5dp"
android:checked="false" />
</merge>
values-v14/compound_switch.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Switch
android:id="#+id/night_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView20"
android:layout_toLeftOf="#+id/textView20"
android:layout_toStartOf="#+id/textView20"
android:layout_marginRight="5dp" />
</merge>
Move your layout that has the switch from the folder values-v14 to a folder called layout-v14. Layouts should be in the layout folder. The values folder is for colors, dimensions, attributes, etc.

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

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>

Categories

Resources