Customizing LineIndicator of ViewPagerIndicator - android

I am new to ViewPagerIndicator. I am using LineIndicator along with my ViewPager. The default look is tiny blue lines wherever you position them.
However, if I want to, say, change the color and the width and height, how would I do that?
Update
If you look at the sample phones shown, the one in the center has red lines at the bottom. The title of the app says "Line / Styled (via layout)". That is what I am trying to achieve.

You just need to style your LinePageIndicator in your .xml layout file.
EX:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<com.viewpagerindicator.LinePageIndicator
android:id="#+id/indicator"
android:padding="5dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
app:strokeWidth="4dp"
app:lineWidth="30dp"
app:unselectedColor="#FF888888"
app:selectedColor="#FF880000"
/>
</LinearLayout>

Related

Android - ViewPager: Tabs with fixed positions

I'm using ViewPager to create a tab layout. It works ok but I want to change it's behavior a bit. When I swipe to a new tab it's title is moved to the center of the width forcing the titles of the other tabs to look kind of compressed. I want all tab titles to remain in a fixed position. I tried modifying the layout a little but I didn't get anywhere... How can I achieve this?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.viewpagerindicator.TitlePageIndicator
android:id="#+id/indicator"
android:padding="10dip"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:background="#000000"
android:textColor="#2FB3E3"
app:footerColor="#2FB3E3"
app:footerLineHeight="1dp"
app:footerIndicatorHeight="3dp"
app:footerIndicatorStyle="underline"
app:selectedColor="#FFFFFF"
app:selectedBold="true"
/>
<com.bill.deuterh.NoSwipeViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
Why don't you use a fragment instead of declaring all in xml? In java file you can have more flexibily, and fragments can be reused..
For a complete example using fragment, you can read here: http://developer.android.com/reference/android/support/v4/view/ViewPager.html

Create layout custom title

I want to create an android interface, something like a launcher. For this, I need to make a custom title bar and 2 borders in each side of the screen.
I have several activities in my app, and I need this to be in all of them, so I need to create independent layouts, one with the custom titlebar and another with the borders. The result may be this:
This is the xml for the borders:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/border_left"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_alignParentLeft="true"
android:background="#000000" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/border_right"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_alignParentRight="true"
android:background="#000000" >
</RelativeLayout>
And this is the xml for the tittle:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:orientation="horizontal"
android:background="#000000" >
The questions are 2:
How can I put in the middle of the titlebar (the red square) a logo (image)?
How can I insert these 2 layouts into the other activities? For example, how could I make my plain main layout include these 2 layouts?
Answer for the second question: include the layout into another layout:
<include
layout = "#layout/custom_tittlebar" >
</include>
I'm still fighting with the titlebar, I want to put the image that way and I'm thinking if this is the best way, or maybe I have to create an image with photoshop setting the logo on it, and then set it as background in the layout.

Android Vertical tabhost

i want to built a vertical Tab host like the below image
i tried with the following code but the tabs are not visible
getTabWidget().setOrientation(LinearLayout.VERTICAL);
is it possible to implement tab host like below.if possible tell me the way to implement tab host like below.and also post the links if there are any built in project's to implement it like the below Image.
(or)
is it possible to add an activity to image view click similar to tab bar click like below
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1));
because if it is possible i will put image views and change the activities on each item click
Help me out in making the vertical tab-host.
You just need to place your tab Widget in a horizontal LinearLayout in your XML file:
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/imageView3" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</android.support.v4.view.ViewPager>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical">
</TabWidget>
</LinearLayout>
</TabHost>
this will place the tabs to the right of the content, if you want it to the left you need to rearrange the order in the XML file.
Better use fragments. Make a layout with vertically aligned buttons and use fragments for transition of pages on button click. Refer this to know more about fragments.
Just to complement Emil Adz answer.
When you add the control to the layout using the graphic tool, this adds all the code necessary for it, but it misses android:orientation="vertical" for every LinerLyout.
Example:
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</LinearLayout>
You have to type it down yourself
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>

how to set tab bar like the one given in image

i m trying to set the tabbar like the one given in the figure
here is my xml file `
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="30sp"
android:layout_marginBottom="40sp"
android:layout_marginLeft="70sp"
android:layout_marginRight="70sp"
android:layout_weight="0"
android:background="#drawable/rounded_corners_white_bg"
android:tabStripEnabled="false" >
</TabWidget>
</LinearLayout>
</TabHost>`
by setting left, right and bottom margins i've got this uptill now.
in this figure the tabbar is shown at the bottom with BLACK background color that's wht i don't want.
because of it's black background color my activity's content are not visible
can anyone help me???????????
I tried your layout file its giving space left side,right side and bottom. here its working fine. Are you using any other layout out side..?or may be due to your #drawable/rounded_corners_white_bg. in background take any other color like "#cd9089".

View over another View

I have some Popups on my screen, and need something not so common.
I Layout my popup with Header + Content + Footer into a LinearLayout. But I need a little arrow to show on my component.
When the popup is above the anchor and the arrow is down, I use the following code to have it drawed.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:id="#+id/header" android:background="#drawable/background_header"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
<HorizontalScrollView android:background="#drawable/background"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:scrollbars="none">
</HorizontalScrollView>
<ImageView android:id="#+id/arrow_down" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="-3dip"
android:src="#drawable/quickcontact_arrow_down" />
</LinearLayout>
In runtime I'm able to place the arrow exactly above the anchor with the following code.
ViewGroup.MarginLayoutParams param = (ViewGroup.MarginLayoutParams) mArrowDown
.getLayoutParams();
param.leftMargin = root.getMeasuredWidth()
- (screenWidth - anchor.getLeft());
And it's show correctly.
Now I need do the same thing but the arrow needs to show in the up side.
My problem is that the arrow need overlap a little over the other View (cause the backgrounds color match them), so this is why it's need to be draw after.
I tried with a FrameLayout and letting "content" has some topMargin, but it's not working.
I know it's can be done with AbsoluteLayout, but I'm avoiding it at all costs.
EDIT:
Following Josh answer, I wrote the following code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:id="#+id/content"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:fadingEdgeLength="0dip">
<RelativeLayout android:id="#+id/header"
android:background="#drawable/background_header" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="wrap_content">
</RelativeLayout>
<HorizontalScrollView android:background="#drawable/background"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:scrollbars="none">
</HorizontalScrollView>
</LinearLayout>
<ImageView android:id="#+id/arrow_up" android:layout_above="#id/content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="#drawable/quickcontact_arrow_up" />
</RelativeLayout>
But I don't know why, the arrow is not show now.
I won't pretend to have read all that xml. I think what you want is RelativeLayout, though. You should be able to use this technique to place any little arrow view where ever you like, relative to the bounds of the RelativeLayout which encompasses it.
If you wrap everything you have in a single RelativeLayout, for instance, and then add, say, a Button as the second item, you can give the button attributes like alignParentRight=true and layout_marginRight=10dp to place the button 10dp from the right edge of the screen, ON TOP of whatever views are already there.

Categories

Resources