Android including layout file (reference id) - android

I am trying to include an existing layout in another layout file (xml). To position those layouts I need to give the included layout an id, so i am able to reference it, e.g.
I am using the following layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
...
</RelativeLayout>
I am including this layout in another layout, like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/container"
android:background="#drawable/bg"
>
<include android:id="#id/bar" layout="#layout/bar"/>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/bar"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
...
</LinearLayout>
</ScrollView>
</RelativeLayout>
This works fine and my ScrollView gets positioned below my bar and I am able to click on the bar, without the click events being intercepted by the ScrollView.
When I am trying to do the same in a different layout file it says that it canĀ“t find the resource #id/bar:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/layoutContainer2"
>
<include android:id="#id/bar" layout="#layout/bar"/>
<ScrollView
android:id="#+id/scrollview2"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="#id/bar"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
...
</LinearLayout>
</ScrollView>
</RelativeLayout>
Anybody knows why that is?

change android:id="#id/bar" to android:id="#+id/someId"

Related

Unwanted margin android

I'm using an image carousel and for more reason there's a margin between the carousel and the title bar or action bar http://imgur.com/a/Pvonn , and therefore I have to add a negative value to the top margin which is not desired...
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mock.vivofusion.MainActivity"
android:background="#f58b4c">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id ="#+id/viewPagerLayout">
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
.......
</RelativeLayout>
swipe_layout.xml(used for the carousel)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id = "#+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
I can also provide the java classes if needed (the code is 'copy pasted' from a website).
LE: How can I make the scroll to be accessible only on the carousel area? Everywhere I swipe the images keep moving.
This may be helpful, android:scaleType="fitStart".
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id = "#+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitStart" />
</LinearLayout>

Scrolling issue - Android Scrollview

I seem to be having an issue getting my app to scroll fully. I think there is an issue with the linear layout but would like your help to solve this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout 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:orientation="vertical"
tools:context="com.app.aks.fragments.ThreeFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
//// some image and text views //////
</LinearLayout>
</LinearLayout>
</ScrollView>
The window only scrolls partially and not all the way to the bottom....Suggestions?
In your MainActivity.java
Or whereever you are using/initializing these views.
Try this for all the textviews/image views. which are nested inside.
view.setMovementMethod(new ScrollingMovementMethod());
The direct child of ScrollView should be another layout that supports multiple children, such as RelativeLayout or LinearLayout.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton ... />
<TextView ... />
<TextView ... />
<TextView ... />
</ScrollView>
Try with setting android:fillViewport="true" on the ScrollView:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">

how to show always a view in the screen

I have this XML for a Activity and I want to show always Gallery view in the screen.When I use this layout and ListView goes bigger Gallary goes under the ListView and out of visible.How can show it always in the screen even ListView goes bigger than the screen size? Using this layout or another type.
<?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:orientation="vertical" >
<ExpandableListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ExpandableListView>
<Gallery
android:id="#+id/gallery_footer_row"
android:layout_width="fill_parent"
/>
</LinearLayout>
<?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:orientation="vertical" >
<ExpandableListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ExpandableListView>
<Gallery
android:id="#+id/gallery_footer_row"
android:layout_width="fill_parent"
/>
</LinearLayout>

How can MapView fill a full parent container?

There is the following simple layout:
<RelativeLayout 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" >
<com.google.android.maps.MapView
android:id="#+id/activityMainPoints"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:apiKey="0JsSnv022MOCCXMAJfsQTVtfCiH37VG5XykFLmQ"
android:clickable="true" />
</RelativeLayout>
As you can see, the MapView must fill the full parent container RelativeLayout, but it isn't! How can I fix it?
android:layout_width="fill_parent"
android:layout_height="fill_parent"
Try this:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activityMainPoints"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0JsSnv022MOCCXMAJfsQTVtfCiH37VG5XykFLmQ"
android:clickable="true"
/>

"android:layout_above" parameter in RelativeLayout

First of all, here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#android:color/white">
<LinearLayout [...]
android:layout_above"#+id/test">
</LinearLayout>
<LinearLayout [...]>
<LinearLayout [...]
android:id="#+id/test"/>
</LinearLayout>
</RelativeLayout>
This xml won't work...
Is there any option to do that? Setting the android:layout_above parameter to a view that's inside another one?
I modified a bit of your code .. please try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#android:color/white">
<LinearLayout [...]
android:id="#+id/test">
</LinearLayout>
<LinearLayout [...]
android:layout_below"#+id/test">
<LinearLayout [...]/>
</LinearLayout>
</RelativeLayout>

Categories

Resources