Aligning ViewPager and TextView Vertically - android

<?xml version="1.0" encoding="utf-8"?>
<!-- Layout-Normal-Portrait -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/thumb_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<android.support.v4.view.ViewPager
android:id="#+id/mypager"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_above="#id/sum_layout"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</android.support.v4.view.ViewPager>
</RelativeLayout>
<RelativeLayout
android:id="#+id/sum_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#id/thumb_layout" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="#string/lorem__ipsum"
android:textColor="#color/black" />
</RelativeLayout>
</RelativeLayout>
As soon as I run the program, it shows a error in the editor saying "error: Error: No resource found that matches the given name (at 'layout_above' with value '#id/sum_layout')." which is at line 22 in this code.
Can any one tell, what is wrong?

I wonder why you are making it so complex.
Anyways here is corrected snippet
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout-Normal-Portrait -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" > <---No need to specify android:orientation
<android.support.v4.view.ViewPager
android:id="#+id/mypager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/textView" />
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:padding="6dp"
android:text="Hello"
android:textColor="#android:color/black" /> <---Place your text String here
</RelativeLayout>

use #+id/sum_layout
and clean Project and run again!

This is because you declare sum_layout id AFTER its first reference.
The best solution is to declare it in the /res/values/ids.xml like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="sum_layout" />
</resources>
And then reference it in all your layouts without the + keyword
<android.support.v4.view.ViewPager
android:layout_above="#id/sum_layout"
/>
And
<RelativeLayout android:id="#id/sum_layout" />

Try This
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/mypager"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</android.support.v4.view.ViewPager>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:textColor="#color/black" />

When you are using relative layout, you are relating the controls with each other.when you add any control you add next control with respect to the control defined before.Likewise here you have defined view pager layout which is under layout having id #+id/sum_layout. but you have defined layout #+id/sum_layout under view pager.so it doesn't get id #+id/sum_layout,so how it will set view pager under the text view.first of all add the view and then add to its under/above.Here is your mistake:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<android.support.v4.view.ViewPager
android:id="#+id/mypager"
android:layout_width="fill_parent"
android:layout_height="300dp">
</android.support.v4.view.ViewPager>
<TextView
android:id="#+id/mytext"
android:text="#string/lorem__ipsum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/mypager"/>
</RelativeLayout>
Set the layout according to this wherever you have to keep to its below or above.
hope it will help you.

Related

Listview error: parsing xml not well-formed (invalid token)

Tried all that I could read on net but to no avail. Getting the above error on this fragment_main.xml code. I want to create a simple listview with some text in linear layout. Please point out the mistake.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff0000cc"
android:textStyle="bold“ />
</TextView>
<ListView android:id="#android:id:listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false">
</ListView>
<TextView android:id="#android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Empty set"/>
</TextView>
</LinearLayout>
Change this
android:textStyle="bold“ />
</TextView>
to
android:textStyle="bold“ /> // this /> indicates the end of tag
Change this
android:textStyle="bold“
to
android:textStyle="bold" // note the ""
Similarly for other textview
android:text="#string/Empty set"/>
</TextView>
Change to
android:text="#string/Empty set"/>
Finally
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff0000cc"
android:textStyle="bold" />
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false" >
</ListView>
<TextView
android:id="#android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Empty set" />
</LinearLayout>
Note : fill_parent (renamed match_parent in API Level 8) tells your view to become as big as its parent view group will allow.
So use match_parent instead of fill_parent.

layout_alignParentBottom not working as expected

I am trying to get a couple of buttons to attach to the bottom of the screen.
For some reason they are attaching themselves to the previous view:
As you can see the buttons are overwriting the previous view.
This is the layout I use:
<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:text_field_element="http://schemas.android.com/apk/res-auto"
xmlns:button_element="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:orientation="vertical"
>
<LinearLayout android:id="#+id/data_entry"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<com.applicat.meuchedet.views.TextFieldElement
android:id="#+id/dental_clinics_search_screen_clinic_type_selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
text_field_element:prompt="#string/dental_clinic_search_screen_dental_clinic_type_prompt"
text_field_element:initial_text="#string/dental_clinic_type_initial"
text_field_element:cursor_visible="false"
/>
<include
layout="#layout/separator_element"
/>
<com.applicat.meuchedet.views.LocationSelector
android:id="#+id/dental_clinics_location_selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<include
layout="#layout/separator_element"
/>
<com.applicat.meuchedet.views.TimeSelector
android:id="#+id/dental_clinics_time_selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<include
layout="#layout/separator_element"
/>
</LinearLayout>
<com.applicat.meuchedet.views.ButtonElement
android:id="#+id/dental_clinics_search_screen_search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
button_element:margin_bottom="10"
/>
<com.applicat.meuchedet.views.ClearButtonElement
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/dental_clinics_search_screen_search_button"
android:layout_alignParentBottom="true"
button_element:margin_bottom="10"
/>
</RelativeLayout>
separator_element.xml
<?xml version="1.0" encoding="UTF-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:layout_marginBottom="15dip"
android:src="#drawable/form_separator"
>
</ImageView>
============================================================================
Edit:
So, it seems that the problem is caused by the fact that the view is put into a ScrollView. We need the ScrollView due to the possibility of small screens.
For some reason it sets the size wrong or something and puts the buttons just below the fields instead of at the very bottom.

Add semi-transparent overlay to activity backround at runtime

I have an app that i set the background to an image from xml. I get the view by calling
setContentView(R.)
.
How can i place a semi-transparent overlay on this background at runtime depending on a condition. I would like to have a red overlay with its alpha set to 50%.
I have tried creating a seperate xml file with the view duplicated and a different image/overlay but its messy as i have to inflate all the buttons/textview when i use the new view.
thanks matt
[edit1]
<?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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/carefreebgscaledlighting"
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/textviewcompanyname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#003F87" />
<TextView
android:id="#+id/textViewYouAreSignedIn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#003F87"
/>
<TextView
android:id="#+id/textViewUnsentTransactions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_below="#id/textViewYouAreSignedIn"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#003F87"
/>
[edit2]
<?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"
>
<RelativeLayout
android:id="#+id/transparentOverlay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/red_transparent" >
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/carefreebgscaledlighting"
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/textviewcompanyname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#003F87" />
<TextView
android:id="#+id/textViewYouAreSignedIn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#003F87"
/>
[edit3]
<?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:id="#+id/ll1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/carefreebgscaledlighting"
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/textviewcompanyname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#003F87" />
.
if(status.equalsIgnoreCase(IN)){
youAreSignedInAt.setText("You are signed in at " + name);
LinearLayout layout =(LinearLayout)findViewById(R.id.ll1);
layout.setBackgroundResource(R.drawable.carefreebgscaledlightingred);
}else{
youAreSignedInAt.setText("You are not signed in");
LinearLayout layout =(LinearLayout)findViewById(R.id.ll1);
layout.setBackgroundResource(R.drawable.carefreebgscaledlighting);
}
Off the top of my head, you could declare the background color including alpha component in a resource file (i.e. colors.xml)
<color name="red_transparent">#66FF0000</color>
And then put a view (i.e. RelativeLayout), on top of the rest of the views.-
<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" >
<!-- All your views -->
<!-- Transparent layer -->
<RelativeLayout
android:id="#+id/transparentOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/red_transparent" />
</RelativeLayout>
All you need to do is changing visibility of R.id.transparentOverlay as you desire.

android swipelist missing attributes

I have the same problem that this user : the other question
But I have the name of the class in my layout xml file correctly typed, and in the xml view it does not give any error, but when I change to graphical layout view I get an error saying :
java.lang.RuntimeException: You forgot the attributes swipeFrontView or swipeBackView.
You can add this attributes or use 'swipelist_frontview' and 'swipelist_backview'
identifiers
I added nineoldandroid and swipe-list jars.
Any tips on this?
Changing the ids in SwipeListView to
swipe:swipeBackView="#+id/swipelist_backview"
swipe:swipeFrontView="#+id/swipelist_frontview"
And in the list item view to
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/swipelist_backview"
...>
...
</RelativeLayout>
<RelativeLayout
android:id="#+id/swipelist_frontview"
...>
...
</RelativeLayout>
</FrameLayout>
Solved the problem for me. I think this bug is somehow related to this pull request https://github.com/47deg/android-swipelistview/pull/11
swipeListView have 2 views as "FrontView"&"BackView"
try this sample xml :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="#+id/back"
style="#style/ListBackContent"
android:layout_width="wrap_content"
android:layout_height="110dp"
android:tag="back" >
<LinearLayout
android:id="#+id/backshowportion"
style="#style/ListBackContent"
android:layout_width="250dp"
android:layout_height="110dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="right|center" >
<TextView
.... />
<TextView
.... />
<TextView
..../>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/front"
style="#style/ListFrontContent"
android:layout_width="match_parent"
android:layout_height="110dp"
android:orientation="vertical"
android:tag="front" >
<TextView
.... />
<TextView
.... />
<TextView
.... />
</RelativeLayout>
</FrameLayout>
You need in you list something like this :
<?xml version="1.0" encoding="utf-8"?>
<com.fortysevendeg.android.swipelistview.SwipeListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="#00000000"
swipe:swipeActionLeft="dismiss"
swipe:swipeBackView="#+id/back"
swipe:swipeCloseAllItemsWhenMoveList="true"
swipe:swipeFrontView="#+id/front"
swipe:swipeMode="both" />

How to add a layout in another one?

I need to hold my every view in one layout, so that i can move them all at once... But when i tried to put them all in a layout which should be in another main layout, they cannot be seen. What am i doing wrong?
I found out that the layout called leftLayout cannot be seen. I made different colours of layouts and it showed me the main one, called menu. I tried visibility true but it didn't work as well.
My design page is like this:
It should appear like this, but i see only white window when i compile...
Here's my Xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/leftLayout"
android:addStatesFromChildren="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="70dp"
android:orientation="vertical" >
<TextView
android:id="#+id/leftMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:enabled="true"
android:text="Left Menu"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<ListView
android:id="#+id/list"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginTop="70dp"
android:enabled="true" >
</ListView>
</RelativeLayout>
</RelativeLayout>
Solved! I figured out that i was just doing mistake in java codes, while setting margin. So here the code's allright.
In relative layout you always need specify the location of each child with respect to the parent or the between the children. Since you have specified the layout all the layouts will be copied one over the other. You can use child alignment options like "ABOVE", "BELOW" w.r.t to other layouts.
The below code looked like what you wanted,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/leftLayout"
android:addStatesFromChildren="true"
android:layout_width="100dp"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_alignleft="#+id/menu" >
<TextView
android:id="#+id/leftMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:enabled="true"
android:text="Left Menu"
android:layout_weight="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<ListView
android:id="#+id/list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:enabled="true"
android:layout_marginTop="50dp"
android:layout_weight="1"
android:layout_below="#+id/leftMenu" >
</ListView>
</RelativeLayout>
</RelativeLayout>
You are using a relative layout yet you have not specified the location of the child views relative to each other.
In Relative layout you must specify this, look here: http://developer.android.com/resources/tutorials/views/hello-relativelayout.html
Did you tried with LinearLayouts?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<LinearLayout
android:id="#+id/leftLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="70dp"
android:orientation="vertical" >
<TextView
android:id="#+id/leftMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:enabled="true"
android:text="Left Menu"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="70dp"
android:enabled="true" >
</ListView>
</LinearLayout>
</LinearLayout>

Categories

Resources