Android Animate GONE visibility - android

in my application i have RelativeLayout with any widgets,into layout and i want to move up that by xml animate. RelativeLayout visibility is GONE and that must be set visibilty to GONE again and move that to up.
my problem is this, after set again visibilty to GONE move animate dont work and after change visibilty to VISIBLE, RelativeLayout can be show but only thats childeren move up, i want to RelativeLayout with all chileds move to top. how to resolve this problem?
XML animation:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="#android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromYDelta="70%p"
android:toYDelta="0%p"
android:duration="800" />
</set>
animate code:
animMoveUp = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animation_move_up);
uiFiller.toolbarLinearlayoutIcons.setVisibility(View.VISIBLE);
uiFiller.toolbarLinearlayoutIcons.startAnimation(animMoveUp);
my layout:
<?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:id="#+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffe67f24"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/main_tsms_actionbar_background" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="38dp"
android:layout_height="38dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="#+id/txtSmsReceiveSlaveMobile"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="#+id/txtSmsReceiveSlaveContactName"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="right|center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#f6f6f6"
android:textSize="#dimen/normal_text_size" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ffffff"
android:minHeight="150dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ListView
android:id="#+id/lvSmsReceiveSlaveList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:divider="#null"
android:listSelector="#android:color/transparent"
android:stackFromBottom="true"
tools:listitem="#layout/activity_sms_receive_slave_item" >
</ListView>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#drawable/gradient_divider" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50dp" >
<TextView
android:id="#+id/sms_counter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="false"
android:layout_alignParentTop="false"
android:gravity="left"
android:paddingLeft="3dp"
android:paddingTop="3dp"
android:textColor="#ff787878"
android:textSize="9sp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff" >
<ImageButton
android:id="#+id/imgbtn_send_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="8dp"
android:background="#drawable/icon_send_sms" />
<EditText
android:id="#+id/smsBody"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_gravity="right|center_vertical"
android:layout_weight="1"
android:background="#ffffff"
android:ems="10"
android:gravity="right|top"
android:hint="#string/hint_enter_text"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:textColor="#000000"
android:textSize="#dimen/small_text_size"
android:windowSoftInputMode="adjustResize" >
<requestFocus />
</EditText>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/toolbarLinearlayoutIcons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:animateLayoutChanges="true"
android:visibility="gone" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="48dp"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/imgbtn_copy_to_clipboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:background="#drawable/icon_copy_to_clipboard" />
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<ImageButton
android:id="#+id/imgbtn_delete_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/icon_delete_sms" />
<TextView
android:id="#+id/TextView02"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<ImageButton
android:id="#+id/imgbtn_share_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/icon_share_sms" />
<TextView
android:id="#+id/TextView03"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<ImageButton
android:id="#+id/imgbtn_forward_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="10dp"
android:background="#drawable/icon_forward_sms" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
in this layout i want to move toolbarLinearlayoutIcons id

You can do with 1 line in xml just put this on parent layout
android:animateLayoutChanges="true"

Use below methods to expand and collapse the desired view :
public void expand(final View v) {
v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
final int targtetHeight = v.getMeasuredHeight();
if (v.isShown()) {
collapse(v);
} else {
v.getLayoutParams().height = 0;
v.setVisibility(View.VISIBLE);
Animation a = new Animation() {
#Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
v.getLayoutParams().height = interpolatedTime == 1 ? LayoutParams.WRAP_CONTENT
: (int) (targtetHeight * interpolatedTime);
v.requestLayout();
}
#Override
public boolean willChangeBounds() {
return true;
}
};
a.setDuration((int) (targtetHeight + 500));
v.startAnimation(a);
}
}
public void collapse(final View v) {
final int initialHeight = v.getMeasuredHeight();
Animation a = new Animation() {
#Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
if (interpolatedTime == 1) {
v.setVisibility(View.GONE);
} else {
v.getLayoutParams().height = initialHeight
- (int) (initialHeight * interpolatedTime);
v.requestLayout();
}
}
#Override
public boolean willChangeBounds() {
return true;
}
};
a.setDuration((int) (v.getLayoutParams().height + 500));
v.startAnimation(a);
}

Related

Animation a layout from bottom to top with fade in

I want a animation that first FadeIn the TextView with id Symbol_no from Bottom to Top Then FadeIn other View on the screen.
symbolnotextview.animate().setDuration(duration).
scaleX(1).scaleY(1).
translationX(0).translationY(0).
setInterpolator(sDecelerator).
withEndAction(new Runnable() {
public void run() {
// Animate the description in after the image animation
// is done. Slide and fade the text in from underneath
// the picture.
mTextView.setTranslationY(-mTextView.getHeight());
mTextView.animate().setDuration(duration/2).
translationY(0).alpha(1).
setInterpolator(sDecelerator);
}
});
But i think this is not what i mean to do .
Here is the XML of the design
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100"
android:id="#+id/toplevel">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="15"
android:background="#drawable/borderframe">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:padding="5dp"
android:src="#drawable/abc_btn_radio_to_on_mtrl_015"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="21477"
android:padding="5dp"
android:gravity="center"
android:background="#drawable/border"
android:id="#+id/Symbol_no"
/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:text="Rohit Shrestha"
android:layout_weight="20"
android:textSize="30sp"
android:gravity="center"
android:id="#+id/name"
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="20"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:id="#+id/parentblock">
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:text="Block"
android:textSize="30sp"
android:gravity="center"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/block_no"
android:background="#drawable/border"/>
<TextView
android:layout_width="120dp"
android:layout_height="fill_parent"
android:text="7"
android:gravity="center"
android:textStyle="bold"
android:layout_alignParentRight="true"
android:textSize="40sp"
android:id="#+id/block_no"
android:background="#drawable/border"/>
</RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:weightSum="100"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:paddingTop="30dp"
android:id="#+id/class_container"
>
<LinearLayout
android:layout_weight="40"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#drawable/border"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Class"
android:textSize="30dp"
android:gravity="center"
android:id="#+id/class_text"
/>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/room_no"
android:textSize="25dp"
android:gravity="center"
android:text="8"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="40"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#drawable/border"
android:gravity="center"
android:layout_marginLeft="15dp">
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Seat"
android:gravity="center"
android:textSize="30dp"
android:id="#+id/Seat_text"
/>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="8"
android:gravity="center"
android:id="#+id/Seat_No"
android:textSize="25dp"
/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:text="Good Luck"
android:gravity="center"
android:id="#+id/display_notification"
android:layout_weight="10"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/Time_Left"
android:text="5 hours to go"
android:gravity="center"
android:textSize="20dp"
android:layout_weight="10"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10dp"
android:text="15 july,2015"
android:gravity="center"
android:layout_weight="10"/>
This is the output :
Try this:
Button btn = (Button)findViewById(R.id.Symbol_no);
DisplayMetrics dis = getResources().getDisplayMetrics();
TranslateAnimation anim = new TranslateAnimation(0, 0, dis.heightPixels, 0);
anim.setDuration(1000);
anim.setAnimationListener(new AnimationListener()
{
#Override
public void onAnimationStart(Animation arg0)
{
}
#Override
public void onAnimationRepeat(Animation arg0)
{
}
#Override
public void onAnimationEnd(Animation arg0)
{
// show whatever you want to show after animation is finished.
}
});
btn.startAnimation(anim);

Show/Hide top bar like chrome, but with some static content and a listview

First let me give a short introduction and then show you what end goal looks:
So far I've added a scrolllistener to my listactivity, so that I can detect scrolling, though it does not give me any animation on android:animateLayoutChanges="true". So when i change the margin's of the view programmatically, it just does these changes instantly, and not that well, any help is most welcomed.
As you can see in my xml, i place the item I'm going to hide slowly first so other will be above it on the Z-axis.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:lector="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:animateLayoutChanges="true"
android:background="#color/background_greyish">
<LinearLayout
android:id="#+id/disappearingHeaderLabel"
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="60dp"
android:animateLayoutChanges="true"
android:layout_height="50dp"
android:background="#color/solid_white"
android:orientation="horizontal"
android:weightSum="7">
<TextView
android:id="#+id/ProductDetailLabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginLeft="15dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dip"
android:layout_weight="4"
android:singleLine="true"
android:text="PRODUKTER"
android:textColor="#color/solid_red"
android:textSize="20dp" />
<Button
android:id="#+id/priceChooserButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="3"
android:background="#drawable/buttonbackground"
android:clickable="true"
android:singleLine="true"
android:text="#string/retailprice"
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold" />
</LinearLayout>
<dk.myapp.mobile.views.PageHeaderView
android:id="#+id/header"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></dk.myapp.mobile.views.PageHeaderView>
<LinearLayout
android:id="#+id/expandingListContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:animateLayoutChanges="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="110dp"
android:layout_above="#+id/paginationBarContainer"
android:orientation="vertical">
<LinearLayout
android:id="#+id/headerLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#color/transparent"
android:orientation="horizontal"
android:weightSum="11">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/sortAmountLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:singleLine="false"
android:text="1354"
android:textColor="#color/solid_red"
android:textSize="15dp" />
<TextView
android:id="#+id/sortLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:text="Produkter"
android:singleLine="true"
android:textColor="#color/solid_red"
android:textSize="15dp" />
</LinearLayout>
<Button
android:id="#+id/filterBtn"
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_weight="4"
android:background="#drawable/button_background_red"
android:clickable="true"
android:singleLine="true"
android:text="#string/retailprice"
android:textColor="#color/solid_white"
android:textSize="15dp"
android:textStyle="bold" />
<Spinner
android:id="#+id/sortSpinner"
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="35dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/spinner_background"
android:drawSelectorOnTop="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:prompt="#string/sort" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="#color/divider_color"></LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#color/divider_color"
android:dividerHeight="1dip"
android:paddingLeft="15dip"
android:scrollbarStyle="outsideInset"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
</LinearLayout>
</LinearLayout>
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
int marginRemoved = firstVisibleItem * 30;
if (marginRemoved > 110) {
marginRemoved = 110;
}
if (previousMarginRemoved != marginRemoved) {
previousMarginRemoved = marginRemoved;
LinearLayout disappearingHeaderContainer = (LinearLayout) findViewById(R.id.disappearingHeaderLabel);
RelativeLayout.LayoutParams disappearingHeaderContainerLayoutParams = (RelativeLayout.LayoutParams) disappearingHeaderContainer.getLayoutParams();
LinearLayout expandingListViewContainer = (LinearLayout) findViewById(R.id.expandingListContainer);
RelativeLayout.LayoutParams expandingListViewContainerParams = (RelativeLayout.LayoutParams) expandingListViewContainer.getLayoutParams();
if (disappearingHeaderStartMargin == -1 && expandingHeaderStartMargin == -1) {
disappearingHeaderStartMargin = disappearingHeaderContainerLayoutParams.topMargin;
expandingHeaderStartMargin = expandingListViewContainerParams.topMargin;
}
float disappearingHeaderTopMarginFloat = disappearingHeaderStartMargin - (marginRemoved * pixelDensity);
int disappearingHeaderTopMargin = Math.round(disappearingHeaderTopMarginFloat);
if (marginRemoved > 50) {
marginRemoved = 50;
}
float expandingContainerTopMarginFloat = expandingHeaderStartMargin - (marginRemoved * pixelDensity);
int expandingContainerTopMargin = Math.round(expandingContainerTopMarginFloat);
disappearingHeaderContainerLayoutParams.setMargins(disappearingHeaderContainerLayoutParams.leftMargin,
disappearingHeaderTopMargin,
disappearingHeaderContainerLayoutParams.rightMargin,
disappearingHeaderContainerLayoutParams.bottomMargin);
expandingListViewContainerParams.setMargins(expandingListViewContainerParams.leftMargin,
expandingContainerTopMargin,
expandingListViewContainerParams.rightMargin,
expandingListViewContainerParams.bottomMargin);
if ((lastChangeDate < System.currentTimeMillis()-100)) {
lastChangeDate = System.currentTimeMillis();
disappearingHeaderContainer.setLayoutParams(disappearingHeaderContainerLayoutParams);
expandingListViewContainer.setLayoutParams(expandingListViewContainerParams);
}
}
}
};

Nothing show after use canvas

I am trying to draw lines and rectangles and the line works perfectly, but when I try to draw the rectangles they doesn't show, so I commented the method and put the rectangles in the background of the layouts, but even they didn't show.
MainActivity.class
protected void onCreate (Bundle savedInstanceState {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
line = (LinearLayout)findViewById(R.id.line);
doLine DoLine = new doLine(line.getContext (),0.2,0.4,0.4);
line.addView(DoLine);
}
DoLine.class
public DoLine (Context context, double first, double second, double third){
super (context);
one = first;
two = second;
three = three;
}
#SuppressLink("DrawAllocation")
public void onDraw (Canvas canvas){
canvas.drawRGB (255,255,255);
Paint pincel1 = new Paint;
pincel1.setColor(getResources().getColor(R.color.yellow));
canvas.drawRect(0,10, getWidth(),40,pincel1);
pincel1.setColor(getResources().getColor(R.colot.green));
canvas.drawRect((float)(getWidth()*one),10, getWidth(),40,pincel1);
pincel1.setColor(getResources().getColor(R.color.blue));
canvas.drawRect((float)(getWidth()*one),10, (float)(getWidth()-(getWidth()*three)),40, pincel1);
activity_main.xml
<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:background="#dcdcdc"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#fdfdfd"
android:orientation="vertical"
android:padding="3dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="#90ffb200"
android:padding="5dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:gravity="right"
android:text="#string/title"
android:textSize="17sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp">
<LineraLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal
<LinearLayout
android:id="#+id/rectyellow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/yellow
</LinearLayout>
<TextView
android:id="#+id/oneText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
<LinearLayout
android:id="#+id/rectblue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/blue"
</LinearLayout>
<TextView
android:id="#+id/twoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
<LinearLayout
android:id="#+id/rectgreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/green"
</LinearLayout>
<TextView
android:id="#+id/threeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Three" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
I have been researching for many many days to find a solution and today i found it, I just needed to change the height of the layout to 40dp
android:layout_height="wrap_content"// change this to 40dp
mainActivity.xml
<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:background="#dcdcdc"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="#fdfdfd"
android:orientation="vertical"
android:padding="3dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="#90ffb200"
android:padding="5dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:gravity="right"
android:text="#string/title"
android:textSize="17sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/line"
android:layout_width="match_parent"
android:layout_height="wrap_content"// change this to 40dp
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp">
<LineraLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal
<LinearLayout
android:id="#+id/rectyellow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/yellow
</LinearLayout>
<TextView
android:id="#+id/oneText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
<LinearLayout
android:id="#+id/rectblue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/blue"
</LinearLayout>
<TextView
android:id="#+id/twoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
<LinearLayout
android:id="#+id/rectgreen"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:background="#drawable/green"
</LinearLayout>
<TextView
android:id="#+id/threeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Three" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
https://www.dropbox.com/s/8dvmgv1k37tnm9f/Sin%20t%C3%ADtulo.png
it's right:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout line = (LinearLayout)findViewById(R.id.line);
DoLine doLine = new DoLine(line.getContext (),0.2,0.4,0.4);
line.addView(doLine);
}
public class DoLine extends View {
double one;
double two;
double three;
public DoLine(Context context, double first, double second, double third) {
super(context);
one = first;
two = second;
three = third;
}
#SuppressLint("DrawAllocation")
public void onDraw(Canvas canvas) {
canvas.drawRGB(255, 255, 255);
Paint pincel1 = new Paint();
pincel1.setColor(Color.YELLOW);
canvas.drawRect(0, 10, getWidth(), 40, pincel1);
pincel1.setColor(Color.GREEN);
canvas.drawRect((float) (getWidth() * one), 10, getWidth(), 40, pincel1);
pincel1.setColor(Color.BLUE);
canvas.drawRect((float) (getWidth() * one), 10, (float) (getWidth() - (getWidth() * three)), 40, pincel1);
}
}
}

How to make a right to left animation in a layout

I am involved with a slide right to left problem. I created it by "hide" and "visible" layout on button clicked. But now I want an animation so that when I clicked on button, a "right to left" animation will happen and when I click again on button, same layout will be "left to right" animation and work as slide layout.
code
final RelativeLayout rightlayout = (RelativeLayout) findViewById(R.id.relativelayout2);
rightlayout.setVisibility(View.GONE);
Button rightbtn = (Button) findViewById(R.id.righttoleft);
rightbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("clickecd");
if(keyright == 0) {
//rightlayout.setVisibility(View.VISIBLE);
keyright++;
slideToLeft(rightlayout);
} else
{
//rightlayout.setVisibility(View.GONE);
TranslateAnimation animate = new TranslateAnimation(0,rightlayout.getWidth(),0,0);
animate.setDuration(1000);
animate.setFillAfter(true);
rightlayout.startAnimation(animate);
keyright--;
}
}
});
// To animate view slide out from left to right
public void slideToRight(View view){
TranslateAnimation animate = new TranslateAnimation(0,view.getWidth(),0,0);
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);
}
// To animate view slide out from right to left
public void slideToLeft(View view){
TranslateAnimation animate = new TranslateAnimation(0,-view.getWidth(),0,0);
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);
}
xml:
<RelativeLayout
android:id="#+id/rightsidemenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/frameLayout1"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="#+id/righttoleft"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:background="#drawable/right_switcher_expanded" />
<RelativeLayout
android:id="#+id/relativelayout2"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/righttoleft"
android:background="#EDEEF3"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical"
android:padding="5dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:gravity="right"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/titleframe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F4F4F4"
android:orientation="horizontal" >
<TextView
android:id="#+id/firsttitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Job and Qualification"
android:textColor="#56A91E" />
</FrameLayout>
<FrameLayout
android:id="#+id/firstframe1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/titleframe"
android:layout_margin="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView81"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Highest qualification" />
<TextView
android:id="#+id/higesttxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="highest qualification" />
</FrameLayout>
<FrameLayout
android:id="#+id/thirdff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/firstframe1"
android:layout_margin="10dp" >
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Occupation" />
<TextView
android:id="#+id/occupationtxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="occupation" />
</FrameLayout>
<FrameLayout
android:id="#+id/thirdfff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/thirdff"
android:layout_marginBottom="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/textView100"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CTC (Income)" />
<TextView
android:id="#+id/incometxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="income" />
</FrameLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:gravity="right"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/titleframe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F4F4F4"
android:orientation="horizontal" >
<TextView
android:id="#+id/firsttitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Family Info"
android:textColor="#56A91E" />
</FrameLayout>
<FrameLayout
android:id="#+id/firstframe11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/titleframe"
android:layout_margin="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView811"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Have children" />
<TextView
android:id="#+id/havechildrntxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="have children" />
</FrameLayout>
<FrameLayout
android:id="#+id/secondfff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/firstframe11"
android:layout_margin="10dp" >
<TextView
android:id="#+id/textView91"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Father Alive" />
<TextView
android:id="#+id/fathrtxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Father Alive" />
</FrameLayout>
<FrameLayout
android:id="#+id/thirdfff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/secondfff"
android:layout_margin="10dp" >
<TextView
android:id="#+id/textView101"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mother Alive" />
<TextView
android:id="#+id/mothertxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Mother alive" />
</FrameLayout>
<FrameLayout
android:id="#+id/thirdffff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/thirdfff"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/textView103"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Brother" />
<TextView
android:id="#+id/brothercounttxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Brother" />
</FrameLayout>
<FrameLayout
android:id="#+id/thirdffff3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/thirdffff"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
<TextView
android:id="#+id/textView104"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sister" />
<TextView
android:id="#+id/sistercounttxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Sister" />
</FrameLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
This code may help you.
Animation Left slide:
Create a file under res/anim/anim_left
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="100%"
android:toXDelta="0%" >
</translate>
Animation Right slide:
Create a file under res/anim/anim_right
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="-100%"
android:toXDelta="0%" >
</translate>
Use it in Activity as:
Animation rightSwipe = AnimationUtils.loadAnimation(this, R.anim.anim_right);
<view>.startAnimation(rightSwipe);
public void slidefromRightToLeft(View view) {
TranslateAnimation animate;
if (view.getHeight() == 0) {
main_layout.getHeight(); // parent layout
animate = new TranslateAnimation(main_layout.getWidth()/2,
0, 0, 0);
} else {
animate = new TranslateAnimation(view.getWidth(),0, 0, 0); // View for animation
}
animate.setDuration(500);
animate.setFillAfter(true);
view.startAnimation(animate);
view.setVisibility(View.VISIBLE); // Change visibility VISIBLE or GONE
}
Solution for those who are looking for right to left animation:
TranslateAnimation animation1 = new TranslateAnimation(0.0f, 0.0f, 1500.0f, 0.0f); // new TranslateAnimation(xFrom,xTo, yFrom,yTo)
animation1.setDuration(1500); // animation duration
animation1.setRepeatCount(4); // animation repeat count if u want to repeat
animation1.setFillAfter(true);
your_view .startAnimation(animation);//your_view for mine is imageView
Solution for those who are looking for repeated animation (for eg. left to right and right to left)
TranslateAnimation animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, 1500.0f); // new TranslateAnimation (float fromXDelta,float toXDelta, float fromYDelta, float toYDelta)
animation.setDuration(1500); // animation duration
animation.setRepeatCount(8); // animation repeat count
animation.setRepeatMode(2); // repeat animation (left to right, right to left)
animation.setFillAfter(true);
your_view.startAnimation(animation);//your_view for mine is imageView
Main layout and back layouts are two linear layouts, when click on button call the startanimation method.
boolean menuOut=false;
public void startAnimation()
{
Animation anim;
int w = mainLayout.getMeasuredWidth();
int h = mainLayout.getMeasuredHeight();
int left = (int) (mainLayout.getMeasuredWidth() * 0.80);
if(!menuOut)
{
anim = new TranslateAnimation(0, -left, 0, 0);
backLayout.setVisibility(View.VISIBLE);
animParams.init(-left, 0, -left + w, h);
}
else
{
anim = new TranslateAnimation(0, left, 0, 0);
animParams.init(0, 0, w, h);
}
anim.setDuration(400);
anim.setAnimationListener(Sample.this);
anim.setFillAfter(true);
mainLayout.startAnimation(anim);
}
AnimParams.java
public class AnimParams {
int left, right, top, bottom;
void init(int left, int top, int right, int bottom) {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
}
You can also use animate().translationXBy([n_pixels]f).
where n_pixels] > 0 moves the object LTR, n_pixels] < 0 moves the object RTL.

Is it possible to check if a specific "TAB" in TabWidget is visible in current View or not?

I have a TabWidget with 5 tabs in it. Tabs : "One","Two","Three","Four","Five". The TabHost is in a HorizontalScrollView. Now I've one arrow (< and >) each on each side of the TabWidget to indicate that there are more tabs in that direction(which are currently not visible in view).
Now what I want to do is, if the first tab is not visible(in current view) then the arrow to left (<) should be visible and if the last tab is not visible(in current view) then the arrow to right should be visible and if both tabs are not visible(in current view) then both arrows should be visible. I tried doing it with:
if (horizontablscrollview.getLeft == 0)
{
arrowRight.setVisiblity(View.VISIBLE)
arrowLeft.setVisiblity(View.INVISIBLE)
}
else if( horizontablscrollview.getRight == 0)
{
arrowLeft.setVisiblity(View.VISIBLE)
arrowRight.setVisiblity(View.INVISIBLE)
}
else if ( horizontablscrollview.getRight == 0 && horizontablscrollview.getLeft == 0)
{
arrowRight.setVisiblity(View.VISIBLE)
arrowLeft.setVisiblity(View.VISIBLE)
}
But this doesn't work, my both tabs are invisible in the start:
my xml looks 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:background="#ffffff" >
<RelativeLayout
android:id="#+id/RL_Header"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_marginBottom="3dip"
android:background="#drawable/gradient" >
<ImageButton
android:id="#+id/btn_Home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="3dp"
android:background="#android:color/transparent"
android:contentDescription="#string/description_home"
android:onClick="onHomeButtonClick"
android:src="#drawable/title_home" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip"
android:background="#android:color/transparent"
android:contentDescription="#string/description_about"
android:onClick="onClickAbout"
android:src="#drawable/title_about" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/FL_Tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/RL_Header" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/FL_Tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/RL_Header" >
<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"
android:background="#ffffff" >
<ImageView android:id="#+id/arrow_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/i_button"
android:layout_alignParentLeft="true"/>
<RelativeLayout
android:id="#+id/rl_tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView android:id="#+id/arrow_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/i_button"
android:layout_alignParentLeft="true"
android:visibility="invisible"/>
<ImageView android:id="#+id/arrow_Right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/i_button"
android:layout_alignParentRight="true"
android:visibility="invisible"/>
<HorizontalScrollView
android:id="#+id/my_scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none"
android:layout_toRightOf="#+id/arrow_left"
android:layout_toLeftOf="#+id/arrow_Right">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:tabStripEnabled="true"/>
</HorizontalScrollView>
</RelativeLayout>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="65dip" >
<RelativeLayout
android:id="#+id/myTabContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dip" >
<TableLayout
android:id="#+id/tabSubs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:layout_marginTop="20dip"
android:gravity="center_horizontal" >
<Button
android:id="#+id/btntestno1"
android:layout_weight="1"
android:gravity="center"
android:padding="20dip"
android:text="Test 1"
android:textColor="#000000" />
<Button
android:id="#+id/btntestno2"
android:layout_weight="1"
android:gravity="center"
android:padding="20dip"
android:text="Test 2"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:gravity="center_horizontal" >
<Button
android:id="#+id/btntestno3"
android:layout_weight="1"
android:gravity="center"
android:padding="20dip"
android:text="Test 3"
android:textColor="#000000" />
<Button
android:id="#+id/btntestno4"
android:layout_weight="1"
android:gravity="center"
android:padding="20dip"
android:text="Test 4"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:gravity="center_horizontal" >
<Button
android:id="#+id/btntestno5"
android:layout_weight="1"
android:gravity="center"
android:padding="20dip"
android:text="Test 5"
android:textColor="#000000" />
<Button
android:id="#+id/btntestno6"
android:layout_weight="1"
android:gravity="center"
android:padding="20dip"
android:text="Test 6"
android:textColor="#000000" />
</TableRow>
</TableLayout>
</RelativeLayout>
</FrameLayout>
</TabHost>
</RelativeLayout>
</RelativeLayout>
Any help would be greatly appreciated.
One solution would be to make you own HorizontalScrollView class and show the ImageViews based on the scroll(although I didn't tested that much the code below should work). Your layout will look like this:
//...
<RelativeLayout
android:id="#+id/rl_tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView android:id="#+id/arrow_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/i_button"
android:layout_alignParentLeft="true"
android:visibility="gone"/>
<ImageView android:id="#+id/arrow_Right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/i_button"
android:layout_alignParentRight="true"
/>
<com.your.package.here.SpecialScroll
android:id="#+id/my_scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:tabStripEnabled="true"/>
</com.your.package.here.SpecialScroll>
</RelativeLayout>
//...
The SpecialScroll class will look like this:
public class SpecialScroll extends HorizontalScrollView {
public interface PositionListener {
public void onLeftArrowRequired(boolean required);
public void onRightArrowRequired(boolean required);
public View implementScrolledView();
}
private PositionListener listener;
public void setPositionListener(PositionListener listener) {
this.listener = listener;
}
public SpecialScroll(Context context) {
super(context);
}
public SpecialScroll(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public SpecialScroll(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (l == 0) {
listener.onLeftArrowRequired(false);
} else {
listener.onLeftArrowRequired(true);
}
View v = listener.implementScrolledView();
Rect r = new Rect();
v.getDrawingRect(r);
if ((r.width() - l) == getWidth()) {
listener.onRightArrowRequired(false);
} else {
listener.onRightArrowRequired(true);
}
}
}
Then in your activity's onCreate method you'll do:
SpecialScroll hsv = (SpecialScroll) findViewById(R.id.my_scrollView);
hsv.setPositionListener(this); // I made the activity implement the SpecialScroll.PositionListener interface
and the activity's implementation of the PositionListener interface is:
#Override
public void onLeftArrowRequired(boolean required) {
if (required) {
((ImageView) findViewById(R.id.arrow_left))
.setVisibility(View.VISIBLE);
} else {
((ImageView) findViewById(R.id.arrow_left))
.setVisibility(View.GONE);
}
}
#Override
public void onRightArrowRequired(boolean required) {
if (required) {
((ImageView) findViewById(R.id.arrow_right))
.setVisibility(View.VISIBLE);
} else {
((ImageView) findViewById(R.id.arrow_right))
.setVisibility(View.GONE);
}
}
#Override
public View implementScrolledView() {
return findViewById(android.R.id.tabs);
}
This isn't an elegant solution, but you could display the left arrow if the x coordinate of the leftmost tab was less than zero and display the right tab if the rightmost tab's x plus its width was greater than the screen width.

Categories

Resources