ivSwapImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
frameFromX = llFrom.getX();
frameFromY = llFrom.getY();
frameToX = llTo.getX();
frameToY = llTo.getY();
if (isSwap) {
llFrom.setX(frameToX);
llFrom.setY(frameToY);
llTo.setX(frameFromX);
llTo.setY(frameFromY);
isSwap = false;
} else {
llFrom.setX(frameToX);
llFrom.setY(frameToY);
llTo.setX(frameFromX);
llTo.setY(frameFromY);
isSwap = true;
}
}
});`
Above write to change Two Linear layout swap to each other position.but need to add animation on that layouts
try this. how add an animation to llFrom and llTo LinearLayout?
Related
Attention! This question is not about dynamic loading of items into a very long ListView.
This is about adding PageUP and PageDown buttons to a ListView so that user can touch the button and scroll ListView page by page. Page means all fully and partially visible items on the screen.
I have partially implemented this in the following code, but my problem is that when I have lets say 10 items of approximately same height in the listview and 7 of them fit into the first page, then when I press PgDown button, user expects that item 8 to be on top of the screen (next page), but because there are only 10 items, ListView scrolls to the bottom of the list and because there is no extra scroll space I have item number 4 on top.
What is the best solution in this situation?
Should I add one item to the end of the list which will make the last page the height of the screen or there are any better options?
Here is my code:
public class cPaginatedListViewHelper {
Activity m_parentActivity;
private ListView mList;
//controls
private LinearLayout m_PagingLL;
//buttons
private ImageButton m_btnPrevPage;
private ImageButton m_btnNextPage;
private ImageButton m_btnExitPaginatedMode;
public cPaginatedListViewHelper(ListActivity mParent) {
this.m_parentActivity = mParent;
m_btnPrevPage=(ImageButton) mParent.findViewById(R.id.btnPrevPage);
m_btnNextPage=(ImageButton) mParent.findViewById(R.id.btnNextPage);
m_btnExitPaginatedMode =(ImageButton) mParent.findViewById(R.id.btnClosePage);
if(m_btnPrevPage!=null) {
m_btnPrevPage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showSiblingPage(-1);
}
});
m_btnPrevPage.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
mList.smoothScrollToPosition(0);
return true;
}
}
);
}
if(m_btnNextPage!=null) {
m_btnNextPage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showSiblingPage(1);
}
});
m_btnNextPage.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
mList.smoothScrollToPosition(mList.getCount());
return true;
}
}
);
}
m_btnExitPaginatedMode.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setEnabled(false);
m_PagingLL.setVisibility(View.GONE);
}
});
mList=mParent.getListView();
m_PagingLL = (LinearLayout) mParent.findViewById(R.id.pageControls);
}
public void updateControlsVisibility()
{
ViewTreeObserver observer = mList.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
if (willMyListScroll()) {
boolean psm = isEnabled();
//enable or disable
m_PagingLL.setVisibility( psm ? View.VISIBLE : View.GONE);
((View)mList).setVerticalScrollbarPosition(psm ? View.SCROLLBAR_POSITION_LEFT: View.SCROLLBAR_POSITION_RIGHT);
}
else
{
m_PagingLL.setVisibility(View.GONE);
((View)mList).setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_RIGHT);
}
}
});
}
private boolean willMyListScroll() {
try {
int pos = mList.getLastVisiblePosition();
if (mList.getChildAt(pos).getBottom() > mList.getHeight()) {
return true;
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
private void showSiblingPage(int shift)
{
if(mList!=null) {
int iScrollPageHeight = mList.getHeight();
mList.scrollListBy(iScrollPageHeight * shift);
}
}
public void setEnabled(boolean psm) {
MyApp.Pref.edit().putBoolean("PSModeEnabled", psm).commit();
}
public boolean isEnabled(){
return MyApp.Pref.getBoolean("PSModeEnabled", false);
}
public void pagedScrollEnableDisable() {
boolean pagingEnabled = isEnabled();
pagingEnabled=!pagingEnabled;
setEnabled(pagingEnabled);
m_PagingLL.setVisibility( pagingEnabled ? View.VISIBLE : View.GONE);
updateControlsVisibility();
}
}
I finished up with using ListView's footer with variable height as shown in the following code:
LayoutInflater inflater = m_parentActivity.getLayoutInflater();
m_footerView = inflater.inflate(R.layout.listview_paged_overscroll, mList, false );
ViewGroup.LayoutParams lp =m_footerView.getLayoutParams();
if(m_tvPageNum!=null) recalcPagination();
if(lp!=null) lp.height = m_extraScrollFooterHeight;
int iFooters = mList.getFooterViewsCount();
if(iFooters==0) mList.addFooterView(m_footerView);
The animation does not work after I set visibility to Invisible, I tried clear animation but not work. I have a button when I click the button it opens a linear layout with animation when I press back button I set the linear layout visibility to invisible again I click the button linear layout appear but no animation please help me.
l1 = (LinearLayout) findViewById(R.id.lnrlgn);
l2 = (LinearLayout) findViewById(R.id.lnrlgn1);
l2.setVisibility(View.INVISIBLE);
Animation uptodown = AnimationUtils.loadAnimation(this,R.anim.uptodown);
viewcrrd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
l2.setAnimation(downtoup);
l2.clearanimation(); // is it right ?
l2.setVisibility(View.VISIBLE);
}
});
public void onBackPressed() {
// super.onBackPressed();
if (back_pressed + TIME_DELAY > System.currentTimeMillis()) {
// super.onBackPressed();
Exitdlg alert = new Exitdlg();
alert.showDialog(LoginActivity.this, "Are You Sure ");
l2.clearAnimation();
} else {
l2.clearAnimation();
l2.setVisibility(View.INVISIBLE);
}
back_pressed = System.currentTimeMillis();
}
Use startAnimation instead of setAnimation
viewcrrd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
l2.setVisibility(View.VISIBLE);
l2.clearanimation();
l2.startAnimation(downtoup);
}
});
I have LinearLayout and a Button, in layout I have a SeekBar and when click button I show or hide LinearLayout, I used View.GONE and View.Visible to hide and show.
It work in many devices but when I test it in Note Edge or cool pad It does not work.
What is happening here?
rlFont = (RelativeLayout) rootView.findViewById(R.id.rlFont);
ivFont.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (ivFont.getDrawable().getConstantState().equals(getActivity().getResources().getDrawable(R.drawable.top_a001).getConstantState())) {
ivFont.setImageResource(R.drawable.top_a002);
rlFont.setVisibility(View.VISIBLE);
rlFont.requestLayout();
} else {
ivFont.setImageResource(R.drawable.top_a001);
rlFont.setVisibility(View.GONE);
rlFont.requestLayout();
}
}
});
This can solve your problem, with this is possible to toggle your button.
boolean isClicked = false;
rlFont = (RelativeLayout) rootView.findViewById(R.id.rlFont);
ivFont.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!isClicked) {
ivFont.setImageResource(R.drawable.top_a002);
rlFont.setVisibility(View.VISIBLE);
rlFont.requestLayout();
isClicked = true;
} else {
ivFont.setImageResource(R.drawable.top_a001);
rlFont.setVisibility(View.GONE);
rlFont.requestLayout();
isClicked = false;
}
}
});
I made animation for background colors of the text views like these:
final TextView textView1 =
(TextView)findViewById(R.id.leftleft);
Resources res = getResources();
final TransitionDrawable crossfaderView1 =
getTransitionDrawableFromColors(R.color.green, R.color.lime);
textView1.setBackground(crossfaderView1);
chooseChangeColors.setOnClickListener(
new View.OnClickListener()
{
#Override
public void onClick(View v) {
if (somethingElseIsPressed == true) {
crossfaderView1.reverseTransition(timeForTransition);
}
else {
crossfaderView1.startTransition(timeForTransition);
}
somethingElseIsPressed = !somethingElseIsPressed;
}
});
But I want to make text in these textViews also changing its own color and text itself.
How can I achieve this?
I have a ScrollView that contains a LinearLayout, in the LinearLayout I have a view that I expand or collapse depending on a button being pushed. This piece works just fine.
What I would like to do is re-position the ScrollView so that when the view is expanded it automatically re-positions the scroll view so that the expanded view is visible. I would like to the view to reposition it self automatically so the user does not have to scroll.
Currently when the view is expanded everything get's pushed down and you have to scroll up to view the newly expanded content. I tried repositioning after the animation has ended but that section of code never fires. Below is my code.
public void animateExpandCollapse(View v) {
View captionLayout = null;
View parentLayout = null;
if(v.getId() == R.id.squareCal) {
captionLayout = (LinearLayout) findViewById(R.id.layout3);
parentLayout = (LinearLayout) findViewById(R.id.squareLayout);
} else if(v.getId() == R.id.circleCal) {
captionLayout = (LinearLayout) findViewById(R.id.layout2);
parentLayout = (LinearLayout) findViewById(R.id.circleLayout01);
}
if (!more) {
dda = new DropDownAnim(captionLayout, 350, false);
more=true;
} else {
dda = new DropDownAnim(captionLayout, 350, true);
more=false;
}
dda.setDuration(350);
parentLayout.startAnimation(dda);
// Here, I want to position ScrollView to the bottom
// After the animation has finished but this never fires.
if(dda.hasEnded() ) {
ScrollView sv = (ScrollView)findViewById(R.id.calScroller);
sv.scrollTo(0, sv.getBottom());
}
return;
}
After searching online I found the following solution. I hope this helps someone.
dda.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
ScrollView sv = (ScrollView)findViewById(R.id.calScroller);
sv.scrollTo(0, sv.getBottom());
}
});