I have implemented a tabs and swipe method inside my application, Here's a link! (this is the nice tutorial)
inside my application in the first TAB I have a ListView and the row are defined in other xml.
this is tab1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/LinearLayout5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/LinearLayout3"
android:layout_alignParentBottom="true"
android:layout_below="#+id/LinearLayout3"
android:layout_marginTop="10dp"
android:background="#ccffcc"
android:orientation="horizontal" >
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<!-- tools:listitem="#layout/row"> -->
</ListView>
</LinearLayout>
</LinearLayout>
this is the row.xml
<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"
android:padding="5dp"
tools:context=".MainActivity" >
<TextView
android:id="#+id/tv_prodotto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="50dp"
android:text="Prodotto"
android:textStyle="bold" android:textColor="#000000" />
<View
android:id="#+id/viewLine"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_below="#id/tv_prodotto"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="#666666" />
<TextView
android:id="#+id/tv_qta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tv_prodotto"
android:layout_marginLeft="50dp"
android:layout_marginTop="3dp"
android:text="Quantita"
android:textColor="#000000"
android:textSize="12sp" />
</RelativeLayout>
the compiler give me an error in the tools:listitem
This is the error: Attribute is missing the Android namespace prefix
before implement the Tabs and swipe method (in a normal application) the tools:listitem="#layout/row" run correctly without compiler error!
How can I resolve this?
I will save you all the trouble.
I hope you're using the eclipse.
When you create new android project in Eclipse, they give you option if you want to implement tab swipe (many other options too).
While creating the new project, on very last window. They give you option for "Navigation Type". This is where you choose if you want to implement tab with swipe feature. To implement tab with swipe, your minimum API has to be 11.
Let me know how it goes, if you have any other question feel free to ask.
Hope this help you out.
Related
How to implement scroll and scroll bar in an android app?
I am new to android development suggest some websites other than android developers website to quickly learn.
Here is an example of a vertical scroll view:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"/>
...
</LinearLayout>
</ScrollView>
And a horizontal scroll view:
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/horizontalScrollView"
android:layout_below="#+id/scrollView"
android:layout_alignParentStart="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2"/>
...
</LinearLayout>
</HorizontalScrollView>
Very simple, open your Android Studio, create new project (blank project). Then in res/layout/activity_main.xml replace with this code:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test2" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test3" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test4" />
.
.
.
.
.
<!-- something you want to display -->
</LinearLayout>
</ScrollView>
For learning android I suggest this website, it has a lot of clean and clear examples for you to try (it's old but for me it's good for beginner):
https://www.tutorialspoint.com/android/index.htm
And again Google is your best friend.
This is a Simple task, you can achieve this by using a ScrollView. Put the Layout in Side a ScrollView and you are ready to go. One thing ScrollView can contain only one ChildView.
Example :
<ScrollView
android:width="match_parent"
android:height="match_parent" >
<LinearLayout
....>
.
.
.
</LinearLayout>
</ScrollView>
Hello I am starting with Android developing. I am just modifying with ECLIPSE an open source example. I have only modified strings.xml and some .png files. In the Android simulator it works perfect but when I try to generate the signed apk file I receive two errors with similar description. This is one of them (the line is marking with *):
Description #+id/about_us_desc_webview is not a sibling in the same RelativeLayout cc3x_about_us.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey_background"
android:orientation="vertical" >
<include
android:id="#+id/cc3x_about_header_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/cc3x_headerlayout" />
<TextView
android:id="#+id/about_us_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/cc3x_about_header_view"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/about_title_label_top_margin"
android:text="#string/about_us_label"
android:textColor="#color/grey_text_color"
android:textSize="#dimen/extra_large_text_size"
android:textStyle="bold" />
<View
android:id="#+id/view1"
android:layout_width="fill_parent"
android:layout_height="#dimen/min_divider_height"
android:layout_below="#+id/about_us_textview"
android:layout_marginLeft="#dimen/about_title_label_side_margin"
android:layout_marginRight="#dimen/about_title_label_side_margin"
android:background="#drawable/about_page_divline" />
<WebView
android:id="#+id/about_us_desc_webview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/view1"
android:layout_marginLeft="#dimen/about_title_label_side_margin"
android:layout_marginRight="#dimen/about_title_label_side_margin"
android:layout_marginTop="#dimen/min_margin_cutoff" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/about_us_desc_webview" >
<TextView
android:id="#+id/about_screen_contact_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
* android:layout_below="#+id/about_us_desc_webview"
android:layout_centerHorizontal="true"
android:text="#string/contact_label"
android:textColor="#color/grey_text_color"
android:textSize="25dip"
android:textStyle="bold" />
<View
android:id="#+id/divider_bottom"
android:layout_width="match_parent"
android:layout_height="#dimen/min_divider_height"
android:layout_below="#+id/about_screen_contact_label"
android:layout_marginLeft="#dimen/about_title_label_side_margin"
android:layout_marginRight="#dimen/about_title_label_side_margin"
android:background="#drawable/about_page_divline" />
<TextView
android:id="#+id/about_xcube_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/divider_bottom"
android:layout_margin="#dimen/max_margin_size"
android:autoLink="web"
android:text="#string/xcube_url"
android:textColor="#color/blue_text_color"
android:textColorLink="#color/blue_text_color"
android:textSize="10dip" />
<TextView
android:id="#+id/about_xcube_contact_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/divider_bottom"
android:layout_margin="#dimen/max_margin_size"
android:autoLink="email"
android:text="#string/xcube_contact_email"
android:textSize="#dimen/small_text_height" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/about_xcube_link"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="#string/about_xcube_address"
android:textColor="#color/grey_text_color"
android:textSize="#dimen/small_text_height" />
</RelativeLayout>
</RelativeLayout>
Any help will be apreciated. Thank you very much!!
The line
android:layout_below="#+id/about_us_desc_webview"
in your TextView is redundant. Since the RelativeLayout already has that attribute, it is useless. You can just erase that line and nothing should change.
And the reason it generates error is that, you can apply features such as below, above.. etc with an element in the same layout. Here "about_us_desc_webview" is out of the RelativeLayout and you cannot position something inside a RelativeLayout with something outside a RelativeLayout.
android:layout_below
Positions the top edge of this view below the given anchor view ID .
When Arise
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:id="#+id/rl_rootHeader"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/rl_Header"
android:layout_below="#+id/rl_rootHeader" // Arise ,In here RelativeLayout is Parent .
>
//
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fillViewport="true"
android:id="#+id/scrollRoot"
android:background="#color/colorWhite"
>
</ScrollView>
Right Way
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:id="#+id/rl_rootHeader"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/rl_Header"
>
//
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:fillViewport="true"
android:id="#+id/scrollRoot"
android:background="#color/colorWhite"
android:layout_below="#+id/rl_rootHeader" // Call Here .This section is Child
>
</ScrollView>
In my case, The problem was with Kotlin Version. I updated the the Kotlin version and the problem "is not a sibling in the same RelativeLayout" resolved
Just remove the lines which are causing error from layout
.xml file
Try refreshing the layout
Your layout will probably change. You can now reset it properly.
If you go to Properties Panel you will see layout:alignComponent has some alignment shown as "Not Found". Just clear it out. In the above example Properties window -> textview -> layout:alignComponent check all alignment values.
Action bar pull to refresh not working in the following case
<?xml version="1.0" encoding="utf-8"?>
<uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ptr_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/top_btns_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<Button
android:id="#+id/allstores_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="all" />
<Button
android:id="#+id/stores_nearme_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="near me" />
<Button
android:id="#+id/stores_ifallow_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="dfdf" />
</LinearLayout>
<ListView
android:id="#+id/store_listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/top_btns_layout"
android:background="#ddd"
android:cacheColorHint="#00000000"
android:divider="#null"
android:dividerHeight="8dp"
android:visibility="visible" >
</ListView>
</RelativeLayout>
I am using this library with sherlock library, and i am also using actionbarsherlock
lib. I dont know how to use AbsPullToRefreshAttacher which is using to add custom views to
pull to refresh, can any one please help me.Thanks in advance.
Supported Views
ActionBar-PullToRefresh has in-built support for:
AbsListView derivatives (ListView & GridView)
ScrollView
WebView
so in your case just sorround your RelativeLayout and ListView with a ScrollView.
if you dont like this solution u have to read the documentation =/
I am using the sliding menu in my application
After clicking on the setting icon I go the following result
The content in the first layout is wrapping, instead I want to hide that part of view
Xml file
<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"
android:background="#drawable/menu_bg"
tools:context=".PrincipalActivity" >
<include layout="#layout/actionbar_menu" android:id="#+id/actionBarMenu"/>
//listview for displaying menu
<ListView
android:id="#+id/listMenu"
android:layout_below="#+id/actionBarMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#282828"
android:dividerHeight="1dip"
android:background="#3F3F3F"
android:fadingEdge="none"
android:listSelector="#drawable/list_selector">
</ListView>
//this is main layout which is visible first time when application starts
<RelativeLayout
android:id="#+id/layoutToMove"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/actionBar"
android:background="#282828">
<include layout="#layout/actionbar_layout" android:id="#+id/actionBar"/>
<ImageButton
android:id="#+id/menuButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignBottom="#+id/actionBar"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:onClick="openCloseMenu"
android:src="#drawable/menu"
android:background="#android:color/transparent" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="asdkjasdksajdkasjdkasjdkasdddddddddddddddddddddddddddddd"
android:textColor="#fff"
android:layout_centerVertical="true"/>
<Button
android:id="#+id/separator"
android:layout_width="1dp"
android:layout_height="50dp"
android:layout_toRightOf="#+id/menuButton"
android:background="#drawable/custom_button_black" />
</RelativeLayout>
Any kind of help will be greatly appreciated
You should consider using jfeinstein10's SlidingMenu. It is quite good and is widely used by many popular Android apps such as Foursquare Rdio, Falcon Pro, ...etc
I am attempting to create some modular UI elements as described at Android Developers - Creating Reusable UI Components, unfortunately I'm not getting the desired result.
The article states:
you can override all the layout parameters. This means that any android:layout_* attribute can be used with the tag.
My XML code looks like this (relevant parts):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="#+id/radio_group"
layout="#layout/radio_buttons"
android:layout_marginTop="75dp"
/>
<include android:id="#+id/player_group"
layout="#layout/player_buttons"
android:layout_alignParentBottom="true"
/>
<EditText android:id="#+id/text_field"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter Your Login ID:"
android:layout_below="#id/player_group"
/>
Here is the first of the included layouts:
<RadioGroup
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/radio_group"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginBottom="20dp"
>
<RadioButton android:id="#+id/radio01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Song #1"
android:paddingLeft="45dp"
/>
[two more identical buttons]
<TextView android:id="#+id/choice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="you have selected:"/>
</RadioGroup>
and the other:
<?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="wrap_content">
<Button android:text="btn01"
android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
/>
<Button android:text="#+id/Button02"
android:id="#+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
/>
<Button android:text="Start Playing"
android:id="#+id/startPlayerBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:onClick="doClick"
/>
</LinearLayout>
Unfortunately - this results in all the included UI elements bunched together on top of each other at the top of the screen. The EditText element aligns correctly, but none of the included elements will respond to any overrided attributes. I have tried a number of different ones with the same non-results.
Note: I also tried putting an android:layout_alignParentBottom="true" parameter into the included layouts thinking that it might need to be in there for it to be overridden, but got the same non-result.
also - the marginTop param doesn't do anything either.
So - any idea what I'm doing wrong?? This is driving me crazy!
Note: there was a question asked a little while ago about how to style included layouts, the answer was a reference to the page on Reusable UI Components. Just want to say that I have read that question and the answer and it hasn't helped.
There is a bug when using include where included layouts are not positioned correctly unless you specify values for android:layout_width and android:layout_height. Try this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="#+id/radio_group"
layout="#layout/radio_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="75dp"
/>
<include android:id="#+id/player_group"
layout="#layout/player_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/radio_group"
/>
<EditText android:id="#+id/text_field"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter Your Login ID:"
android:layout_below="#id/player_group"
/>