Not shown TextView after setting VISIBLE from GONE in animation - android

trying to make showing LinarLayout from GONE state to VISIBLE with "roll down" animation. On this Layout exist TextView. Seems to all work fine but, a TextView not shown after animation.
What I do wrong?
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="#+id/ll_info">
<TextView
android:id="#+id/bayer_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="#string/buyer_note"/>
<RelativeLayout
android:id="#+id/button_continue"
android:layout_width="match_parent"
android:layout_height="54dp"
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:background="#drawable/button_register"
android:drawableEnd="#drawable/ic_arrow_forward_white_24dp">
<TextView
android:id="#+id/btn_cont_caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Войти"
android:textColor="#android:color/white"
android:textSize="20sp"
android:fontFamily="fonts/SF-UI-Display-Regular.ttf"
android:layout_centerInParent="true" />
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView"
android:layout_centerVertical="true"
android:layout_alignParentEnd="false"
android:src="#drawable/ic_door"
android:layout_toRightOf="#+id/btn_cont_caption"
android:layout_marginLeft="10dp"
android:scaleType="fitCenter" />
</RelativeLayout>
</LinearLayout>
And animation code:
final LinearLayout ll_info = (LinearLayout)findViewById(R.id.ll_info);
class scaleAnimation extends Animation {
public LinearLayout ll;
public int newHeight;
public void scaleTopHeight(int height)
{
newHeight = height;
}
public void setLayout(LinearLayout layout) {
ll = layout;
}
}
final LinearLayout ll_info = (LinearLayout)findViewById(R.id.ll_info);
scaleAnimation h = new scaleAnimation() {
#Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
ll.getLayoutParams().height = interpolatedTime == 1
? LinearLayout.LayoutParams.WRAP_CONTENT
: (int)(newHeight * interpolatedTime);
ll.requestLayout();
}
};
h.setDuration(300);
h.setLayout(ll_info);
ll_info.setVisibility(View.VISIBLE);
ll_info.measure(View.MeasureSpec.makeMeasureSpec(((LinearLayout)ll_info.getParent()).getWidth(), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(((LinearLayout)ll_info.getParent()).getHeight(), View.MeasureSpec.AT_MOST));
h.scaleTopHeight(ll_info.getMeasuredHeight());
ll_info.getLayoutParams().height=1;
ll_info.startAnimation(h);

<RelativeLayout
android:id="#+id/button_continue"
android:layout_width="match_parent"
android:layout_height="54dp"
**android:layout_centerHorizontal="true"** /////
remove this
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:background="#drawable/button_register"
android:drawableEnd="#drawable/ic_arrow_forward_white_24dp">
<TextView
android:id="#+id/btn_cont_caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Войти"
android:textColor="#android:color/white"
android:textSize="20sp"
android:fontFamily="fonts/SF-UI-Display-Regular.ttf"
android:layout_centerInParent="true" />
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:id="#+id/imageView"
android:layout_centerVertical="true"
android:layout_alignParentEnd="false"
android:src="#drawable/ic_door"
android:layout_toRightOf="#+id/btn_cont_caption"
android:layout_marginLeft="10dp"
android:scaleType="fitCenter" />
</RelativeLayout>
i think this is your xml file issue ,your relativelayout in center_horizontal and all the childs are in center in parent.so textview hides over imageview. Try it and let me know.

Related

Need to place the clicked item clicked center of the screen, in Horizontal Scrollview

I have populate images dynamically in a linear layout, which is placed inside Horizontal Scrollview. I have enabled auto scroll the horizontal scrollview, with 1 min delay. I have set left and right padding to the horizontal scrollview, as it appears from center of the screen and scrolls to left and end at center of the screen. Auto scroll works fine. My issue is when I click on the images inside the scrollview, I need to bring that image to center of the screen, and continue auto scrolling. I have searched and found answer to place the clicked item center, from the answer for this question Android : Locating the item at center position of the screen after selecting it ,In the horizontalscrollview. But in my case, clicked item, not coming to center.
final int duration = 1000;
final int pixelsToMove = 50;
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final Runnable SCROLLING_RUNNABLE = new Runnable() {
#Override
public void run() {
horizontalScrollView1.smoothScrollBy(pixelsToMove, 0);
mHandler.postDelayed(this, duration);
}
};
HorizontalScrollView horizontalScrollView1 = (HorizontalScrollView) findViewById(R.id.horizontalScrollView1);
LinearLayout layLandmarks = (LinearLayout) findViewById(R.id.layLandmarks);
final ImageView[] dynamic_imageView = new ImageView[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
dynamic_imageView[i] = new ImageView(Activity.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(70, 70);
dynamic_imageView[i].setLayoutParams(lp);
Glide.with(Activity.this)
.load(imageUrl)
.override(30, 30)
.error(R.drawable.button_white_color1)
.into(dynamic_imageView[i]);
dynamic_imageView[i].setId(i);
dynamic_imageView[i].setTag("landmarkName");
layLandmarks.addView(dynamic_imageView[i], i);
horizontalScrollView1.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
int padding = getResources().getDisplayMetrics().widthPixels / 2;
horizontalScrollView1.setPadding(padding, 0, padding, 0);
horizontalScrollView1.setClipToPadding(false);
}
});
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
final int width = size.x;
dynamic_imageView[i].setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int center = (width - dynamic_imageView[i].getWidth())/2;
horizontalScrollView1.scrollTo(dynamic_imageView[i].getLeft() - center, dynamic_imageView[i].getTop());
}
});
}
mHandler.postDelayed(SCROLLING_RUNNABLE, 100);
Adding my layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/black_transparent_background">
<VideoView
android:id="#+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
<Button
android:id="#+id/btnBack"
android:layout_width="15dp"
android:layout_height="20dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="25dp"
android:background="#drawable/back_arrow" />
<TextView
android:id="#+id/txtEventTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="25dp"
android:layout_toRightOf="#id/btnBack"
android:text="Santa Rosa Marathon"
android:textColor="#color/white"
android:textSize="#dimen/text_24" />
<Button
android:id="#+id/btnCamera"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_margin="20dp"
android:background="#drawable/camera_icon_white" />
<RelativeLayout
android:id="#+id/laySeekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/seekBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="17dp"
android:layout_marginRight="17dp"
android:background="#drawable/seekbar_layout_background">
<SeekBar
android:id="#+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progressBackgroundTint="#color/white"
android:thumb="#drawable/seekbar_thumb"
android:visibility="gone"
/>
</RelativeLayout>
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:id="#+id/layLandmarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/laySeekbarText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/btnCircle"
android:layout_centerInParent="true"
android:layout_marginBottom="5dp"
android:background="#drawable/seekbar_text_back">
<TextView
android:id="#+id/seekBarProgressValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:padding="2dp"
android:text="0 mi"
android:textColor="#color/black" />
<TextView
android:id="#+id/txtVideoElevationValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/seekBarProgressValue"
android:layout_centerHorizontal="true"
android:padding="2dp"
android:text="0 sqft"
android:textColor="#color/black" />
</RelativeLayout>
<Button
android:id="#+id/btnCircle"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:background="#drawable/seekbar_thumb" />
<Button
android:id="#+id/btnStart"
android:layout_width="20dp"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:background="#drawable/start_icon" />
<ProgressBar
android:id="#+id/videoProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>

Add labels above Seekbars steps with different font size, vertically aligned to seekbars thumb

I would like to create a Seekbar, above which there will be text label on each Seekbar step, what it should look like is shown in below image
this is the expected result, for which what i have done,
<RelativeLayout
android:id="#+id/layout_font_size"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtFont_size_hint"
style="#style/textStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Aa" />
<LinearLayout
android:id="#+id/layout_seekbar_interval_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/txtFont_size_hint"
android:layout_marginLeft="16dp"
android:layout_marginRight="#dimen/margin_16dp"
android:orientation="horizontal"
android:weightSum="5">
<TextView
android:id="#+id/txtSize_14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false"
android:gravity="center"
android:text="#string/setting_font_text"
android:textSize="#dimen/font_size_14" />
<TextView
android:id="#+id/txtSize_18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false"
android:gravity="center"
android:text="#string/setting_font_text"
android:textSize="#dimen/font_size_18sp" />
<TextView
android:id="#+id/txtSize_24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false"
android:gravity="center"
android:text="#string/setting_font_text"
android:textSize="#dimen/font_size_24sp" />
<TextView
android:id="#+id/textSize_30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false"
android:gravity="center"
android:text="#string/setting_font_text"
android:textSize="#dimen/font_size_30sp" />
<TextView
android:id="#+id/txtSize_36"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false"
android:gravity="center"
android:text="#string/setting_font_text"
android:textSize="#dimen/font_size_36sp" />
</LinearLayout>
<SeekBar
android:id="#+id/seekBarSetting_font_size"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_below="#id/layout_seekbar_interval_holder"
android:layout_marginLeft="#dimen/margin_16dp"
android:layout_marginRight="#dimen/margin_16dp"
android:max="4"
android:theme="#style/seekBarYelloStyle" />
</RelativeLayout>
Output of this is
the Layout looks similar to what is expected but, while moving the seekbar thumb, the thumb is not vertically aligned with the TextView so the problem here is the seekbar thumb is not vertically aligend with the text indicating the steps of seekBar.
I had also tried calculating the exact position of TextView by dividing the seekbars width by steps (Here we have 5 steps but first one is on 0th position so i divided the total seekbar Width by 4 and then placed each text accordingly) but didn't got the expected solution.
I am bit confused here, and want a simple solution as soon as possible.
P.S: ScreenShot of output of view created dynamically is also attached for reference
layout for this :
<?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/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="android.sample.MainActivity">
<TextView
android:id="#+id/txtFont_size_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sizes"/>
<LinearLayout
android:id="#+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:weightSum="5">
<LinearLayout
android:id="#+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="5">
<TextView
android:id="#+id/txtSize1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/setting_font_text"
android:textSize="15sp"/>
<TextView
android:id="#+id/txtSize_18"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/setting_font_text"
android:textSize="20sp"/>
<TextView
android:id="#+id/txtSize_24"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false"
android:gravity="center"
android:text="#string/setting_font_text"
android:textSize="25sp"/>
<TextView
android:id="#+id/textSize_30"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false"
android:gravity="center"
android:text="#string/setting_font_text"
android:textSize="30sp"/>
<TextView
android:id="#+id/txtSize_36"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false"
android:gravity="center"
android:text="#string/setting_font_text"
android:textSize="35sp"/>
</LinearLayout>
<SeekBar
android:id="#+id/seekBarSetting_font_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="4"/>
Now what i have done is aligned the width of Seekbar till the center of the last TextView which in this case is txtSize_36
and have set the ems as android:max="4" so there are five possible values(you can change this to as much as you want)
Code for Activity is :
public class MainActivity extends AppCompatActivity {
SeekBar seekBar;
private LinearLayout bar, ll;
TextView txtSize_14, txtSize_36;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekBar = (SeekBar) findViewById(R.id.seekBarSetting_font_size);
txtSize_14 = (TextView) findViewById(R.id.txtSize1);
txtSize_36 = (TextView) findViewById(R.id.txtSize_36);
ll = (LinearLayout) findViewById(R.id.ll);
}
float density;
#Override
protected void onResume() {
super.onResume();
ViewTreeObserver vto = ll.getViewTreeObserver();
//****old code (may not work on all orientations)****
/*vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
ll.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
ll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
int width = ll.getMeasuredWidth();
int height = ll.getMeasuredHeight();
ViewGroup.LayoutParams params = seekBar.getLayoutParams();
density = getResources().getDisplayMetrics().density;
int newwidth = (int) (txtSize_14.getLeft() / density);
newwidth = newwidth+ (txtSize_36.getLeft() + txtSize_36.getRight()) / 2;
params.width = newwidth;
seekBar.setLayoutParams(params);
}
});*/
//****new code (should work on all orientations)****
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
ll.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
ll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
seekBar.setPadding(15, 0, 15, 0);
seekBar.setX(((txtSize_14.getLeft() + txtSize_14.getRight()) / 2) - 15);
ViewGroup.LayoutParams params = seekBar.getLayoutParams();
int centerwidth = ((txtSize_36.getLeft() + txtSize_36.getRight()) / 2) - ((txtSize_14.getLeft() + txtSize_14.getRight()) / 2) + 15;
params.width = centerwidth;
seekBar.setLayoutParams(params);
}
});
}
}
Here is screenshot for reference (I have clubbed for all positions of seekbar):
Frankly speaking it took me a while to sort this out using XML only.
The first and last label are differently positioned than the others....
In case you will change the size of the thumb from 15dp - you must also change the margin of first and last TextView and size of Spaces (margin + Space = thumb size)
preview
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingRight="0dp"
android:paddingLeft="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="0dp">
<TextView
android:text="7 days"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#color/colorPrimaryBackground"
android:gravity="left|center"
android:textSize="#dimen/textSize_smallest"
android:layout_weight="0.5"
android:layout_marginLeft="5dp"/>
<Space
android:layout_width="10dp"
android:layout_height="match_parent"/>
<TextView
android:text="1 month"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#color/colorPrimaryBackground"
android:gravity="center"
android:textSize="#dimen/textSize_smallest"
android:layout_weight="1"
android:layout_marginRight="0dp"
android:id="#+id/textView" />
<TextView
android:text="3 months"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#color/colorPrimaryBackground"
android:gravity="center"
android:textSize="#dimen/textSize_smallest"
android:layout_weight="1"
android:layout_marginRight="0dp"/>
<TextView
android:text="1 year"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#color/colorPrimaryBackground"
android:gravity="center"
android:textSize="#dimen/textSize_smallest"
android:layout_weight="1"
android:layout_marginLeft="0dp"/>
<TextView
android:text="3 years"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#color/colorPrimaryBackground"
android:gravity="center"
android:textSize="#dimen/textSize_smallest"
android:layout_weight="1"
android:layout_marginLeft="0dp"/>
<Space
android:layout_width="10dp"
android:layout_height="match_parent"/>
<TextView
android:text="5 years"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#color/colorPrimaryBackground"
android:gravity="right|center"
android:textSize="#dimen/textSize_smallest"
android:layout_weight="0.5"
android:layout_marginRight="5dp"/>
</LinearLayout>
</RelativeLayout>

TextView and ImageView not changing on click

I have an activity with three fragments placed in a ViewPager. On the first two fragments I have a list that drops down, kind of like an animated ExpandableListView but it is a simple RelativeLayout containing a TextView and ImageView, when pressed slides down a LinearLayout containing some elements. On clicking the RelativeLayout the followig actions are taken:
change the background color of the clicked RelativeLayout (works every time for every layout in every fragment)
change the color of the text in TextView (works every time for the first element I'll explain below)
animate the image, an arrow to change color and rotate (also works but for the first element)
The problem is as follows:
the first fragment contains only one list (a RelativeLayout that shows or hides a LinearLayout) and it works fine the background, text color and image change and the image rotates and the Linearlayout slides up and down correspondingly. The second fragment contains 4 such groupings (RelativeLayout controlling LinearLayout) and on the first time this fragment is shown only the first grouping seems to work. The other three change background and slide the Linearlayout but as far as i can tell it keeps the same color and the same image (there are two colors a white and an orange that change and since the background changes from orange to white i assume the text stays white instead of changing to orange, same goes for the image).
The punchline:
when I leave it for a few seconds and click it again it works fine, everything changes accordingly, and if i for instance flip to the third fragment and back to the second it works. On the other hand if I start the app, got to the second fragment, back to the first, and to the second again it doesn't work.
I don't know if this has something to do with the GC and recycling views or something else.
XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/nutritionList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/aboutWetFood"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:clickable="false"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/wetSub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:orientation="vertical"
android:visibility="gone" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginBottom="1dp"
android:background="#EDEDED" >
<TextView
android:id="#+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:text="SUB MENU 1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/my_yellow" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginBottom="1dp"
android:background="#EDEDED" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:text="SUB MENU 1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/my_yellow" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/wetLayout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/my_yellow"
android:clickable="true"
android:onClick="openNutrition"
android:tag="wet" >
<TextView
android:id="#+id/wetTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:text="#string/wet_food"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white" />
<ImageView
android:id="#+id/wetArrow"
android:layout_width="12dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="30dp"
android:src="#drawable/arrow_right_white" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/aboutDryFood"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:clickable="false"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/drySub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:orientation="vertical"
android:visibility="gone" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginBottom="1dp"
android:background="#EDEDED" >
<TextView
android:id="#+id/TextView06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:text="SUB MENU 1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/my_yellow" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginBottom="1dp"
android:background="#EDEDED" >
<TextView
android:id="#+id/TextView05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:text="SUB MENU 1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/my_yellow" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/dryLayout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/my_yellow"
android:clickable="true"
android:onClick="openNutrition"
android:tag="dry" >
<TextView
android:id="#+id/dryTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:text="#string/dry_food"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white" />
<ImageView
android:id="#+id/dryArrow"
android:layout_width="12dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="30dp"
android:src="#drawable/arrow_right_white" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/whyMixedFeeding"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:clickable="false"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/mixedSub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:orientation="vertical"
android:visibility="gone" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginBottom="1dp"
android:background="#EDEDED" >
<TextView
android:id="#+id/TextView08"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:text="SUB MENU 1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/my_yellow" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginBottom="1dp"
android:background="#EDEDED" >
<TextView
android:id="#+id/TextView07"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:text="SUB MENU 1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/my_yellow" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/mixedLayout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/my_yellow"
android:clickable="true"
android:onClick="openNutrition"
android:tag="mixed" >
<TextView
android:id="#+id/mixedTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:text="#string/mixed_feeding"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white" />
<ImageView
android:id="#+id/mixedArrow"
android:layout_width="12dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="30dp"
android:src="#drawable/arrow_right_white" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/nutritionOralCare"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:clickable="false"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/oralSub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:orientation="vertical"
android:visibility="gone" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginBottom="1dp"
android:background="#EDEDED" >
<TextView
android:id="#+id/TextView09"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:text="SUB MENU 1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/my_yellow" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginBottom="1dp"
android:background="#EDEDED" >
<TextView
android:id="#+id/TextView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:text="SUB MENU 1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/my_yellow" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/oralLayout"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/my_yellow"
android:clickable="true"
android:onClick="openNutrition"
android:tag="oral" >
<TextView
android:id="#+id/oralTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:text="#string/oral_care_caps"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white" />
<ImageView
android:id="#+id/oralArrow"
android:layout_width="12dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="30dp"
android:src="#drawable/arrow_right_white" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
Methods for changing and animating the views:
public void openNutrition(View view) {
String viewTag = view.getTag().toString();
if (viewTag.equals("wet")) {
nutrition = (RelativeLayout) findViewById(R.id.wetLayout);
nutritionSub = (LinearLayout) findViewById(R.id.wetSub);
nutritionTitle = (TextView) findViewById(R.id.wetTitle);
nutritionArrow = (ImageView) findViewById(R.id.wetArrow);
animate();
}
else if (viewTag.equals("dry")) {
nutrition = (RelativeLayout) findViewById(R.id.dryLayout);
nutritionSub = (LinearLayout) findViewById(R.id.drySub);
nutritionTitle = (TextView) findViewById(R.id.dryTitle);
nutritionArrow = (ImageView) findViewById(R.id.dryArrow);
animate();
}
else if (viewTag.equals("mixed")) {
nutrition = (RelativeLayout) findViewById(R.id.mixedLayout);
nutritionSub = (LinearLayout) findViewById(R.id.mixedSub);
nutritionTitle = (TextView) findViewById(R.id.mixedTitle);
nutritionArrow = (ImageView) findViewById(R.id.mixedArrow);
animate();
}
else if (viewTag.equals("oral")) {
nutrition = (RelativeLayout) findViewById(R.id.oralLayout);
nutritionSub = (LinearLayout) findViewById(R.id.oralSub);
nutritionTitle = (TextView) findViewById(R.id.oralTitle);
nutritionArrow = (ImageView) findViewById(R.id.oralArrow);
animate();
}
else if (viewTag.equals("changeMix")) {
nutrition = (RelativeLayout) findViewById(R.id.changeMixLayout);
nutritionSub = (LinearLayout) findViewById(R.id.foodTypeLayout);
nutritionTitle = (TextView) findViewById(R.id.changeMixText);
nutritionArrow = (ImageView) findViewById(R.id.changeMixArrow);
animate();
}
}
private void animate() {
if (nutritionSub.getVisibility() == View.GONE) {
nutritionSub.setVisibility(View.VISIBLE);
nutrition.setBackgroundColor(getResources().getColor(R.color.white));
nutritionTitle.setTextColor(getResources().getColor(
R.color.my_yellow));
nutritionArrow.setImageDrawable(getResources().getDrawable(
R.drawable.arrow_right_orange));
r = new RotateAnimation(currentPos, degrees,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
/* Setting arrow animation properties */
setArrowAnimation();
Animation slideDown = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.slide_down);
nutritionArrow.startAnimation(r);
nutritionSub.startAnimation(slideDown);
} else {
nutrition.setBackgroundColor(getResources().getColor(
R.color.my_yellow));
nutritionTitle.setTextColor(getResources().getColor(R.color.white));
nutritionArrow.setImageDrawable(getResources().getDrawable(
R.drawable.arrow_right_white));
r = new RotateAnimation(degrees, currentPos,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
/* Setting arrow animation properties */
setArrowAnimation();
Animation slideUp = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.slide_up);
slideUp.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
nutritionSub.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
nutritionArrow.startAnimation(r);
nutritionSub.startAnimation(slideUp);
}
}
private void setArrowAnimation() {
r.setInterpolator(new LinearInterpolator());
r.setDuration(500);
r.setFillEnabled(true);
r.setFillAfter(true);
}
nutrition,nutritionSub,nutritionTitle,nutritionArrow are declared as global private variables
Update
Running a log on my fragment class that extends Fragment and on OnPageChangeListener's method onPageSelected() shows that tags are set properly and visible. The issue seems to be related to the lifecycle of fragments since the changes to the text and image only occur when I flip through ALL three fragments and then return to the second.
Setting the pager:
List<Fragment> fragments = getFragments();
pageAdapter = new NutritionPageAdapter(getSupportFragmentManager(),
fragments);
ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
pager.setAdapter(pageAdapter);
getFragments()
private List<Fragment> getFragments() {
List<Fragment> fList = new ArrayList<Fragment>();
fList.add(NutritionFragment.newInstance("Menu"));
fList.add(NutritionFragment.newInstance("Nutrition"));
fList.add(NutritionFragment.newInstance("Transition"));
return fList;
}
My Fragment class
public static final String FRAGMENT_TITLE = "FRAGMENT_TITLE";
private View v;
public static final NutritionFragment newInstance(String string) {
NutritionFragment f = new NutritionFragment();
Bundle b = new Bundle(1);
b.putString(FRAGMENT_TITLE, string);
f.setArguments(b);
return f;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String screen = getArguments().getString(FRAGMENT_TITLE);
if (screen.equals("Menu")) {
v = inflater.inflate(R.layout.nutrition_menu_activity_layout,
container, false);
} else if (screen.equals("Transition")) {
v = inflater.inflate(R.layout.nutrition_transition_activity_layout,
container, false);
} else {
v = inflater.inflate(R.layout.nutrition_nutrition_activity_layout,
container, false);
}
return v;
}

Not getting RelativeLayout's getHeight() after setting Visibility Visible from Visiblity GONE

What i want is, when i click on Dashboard Button it will open like a SlidingDrawer and after it opened when clicked on it again it will close.
i use this custom drawer because SlidingDrawer is Deprecated.
now the problem is, its working properly except first time when i click on Button it'll open really fast without any animation, but closes properly and after that works fine.
i found the problem is when i make RelativeLayout Visible and try to calculate its getHeight() it will give zero initially, and after that gives proper height.
here's LogCat:
Here's my XML File.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relLayOne"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#0000" >
<Button
android:id="#+id/btnNEWCLICK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/dashboard" />
<RelativeLayout
android:id="#+id/relLayTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/btnNEWCLICK"
android:background="#000"
android:visibility="gone" >
<Button
android:id="#+id/loc"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#000"
android:gravity="left|center_vertical"
android:paddingLeft="5dp"
android:text="My Location"
android:textColor="#fff"
android:textSize="20sp" />
<View
android:layout_width="0.1dp"
android:layout_height="108dp"
android:layout_centerInParent="true"
android:layout_marginBottom="15dp"
android:layout_marginTop="15dp"
android:background="#fff" />
<Button
android:id="#+id/phot"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:background="#000"
android:gravity="left|center_vertical"
android:paddingLeft="5dp"
android:text="Photos"
android:textColor="#fff"
android:textSize="20sp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/phot"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#fff" />
<Button
android:id="#+id/free"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/loc"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#000"
android:gravity="left|center_vertical"
android:paddingLeft="5dp"
android:text="Free stuff"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:id="#+id/leade"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/phot"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:background="#000"
android:gravity="left|center_vertical"
android:paddingLeft="5dp"
android:text="Leaderboard"
android:textColor="#fff"
android:textSize="20sp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/leade"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#fff" />
<Button
android:id="#+id/live"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/free"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#000"
android:gravity="left|center_vertical"
android:paddingLeft="5dp"
android:text="Live Action"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:id="#+id/home"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/leade"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:background="#000"
android:gravity="left|center_vertical"
android:paddingLeft="5dp"
android:text="Home"
android:textColor="#fff"
android:textSize="20sp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.1dp"
android:layout_below="#+id/home"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#fff" />
<Button
android:id="#+id/app"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/live"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="#000"
android:gravity="left|center_vertical"
android:paddingLeft="5dp"
android:text="App stats"
android:textColor="#fff"
android:textSize="20sp" />
</RelativeLayout>
</RelativeLayout>
Here's The Code::
public class MoveView extends LinearLayout{
private Button openCloseButton;
private boolean isVisible = false;
private RelativeLayout relLayTwo, relLayOne;
private float animationHeight = 300.0f;
public MoveView(Context context , AttributeSet attr) {
super(context, attr);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.in, this);
relLayTwo = (RelativeLayout) findViewById(R.id.relLayTwo);
//relLayOne = (RelativeLayout) findViewById(R.id.relLayOne);
openCloseButton = (Button) findViewById(R.id.btnNEWCLICK);
openCloseButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
toggle();
}
});
Log.d("test", "before "+relLayTwo.getHeight());
if (relLayTwo.getHeight() == 0){
relLayTwo.setVisibility(View.VISIBLE);
relLayTwo.invalidate();
relLayTwo.refreshDrawableState();
//rel.setVisibility(View.INVISIBLE);
relLayTwo.setVisibility(View.GONE);
Log.d("test", "after "+relLayTwo.getHeight());
}
}
public void toggle() {
TranslateAnimation anim = null;
isVisible = !isVisible;
if (isVisible) {
relLayTwo.setVisibility(View.VISIBLE);
anim = new TranslateAnimation(0.0f, 0.0f, relLayTwo.getHeight(), 0.0f);
Log.d("test", " rel Height "+relLayTwo.getHeight());
} else {
Log.d("test", " rel Height else "+relLayTwo.getHeight() );
anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, relLayTwo.getHeight());
anim.setAnimationListener(collapseListener);
}
anim.setDuration(600);
anim.setInterpolator(new AccelerateInterpolator(1.0f));
startAnimation(anim);
}
Animation.AnimationListener collapseListener = new Animation.AnimationListener() {
public void onAnimationEnd(Animation animation) {
relLayTwo.setVisibility(View.GONE);
}
public void onAnimationRepeat(Animation animation) {
// not needed
}
public void onAnimationStart(Animation animation) {
// not needed
}
};
}
by using onMeasure() method.
#
Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Log.d("test", " RelativeLAyout In onMeaseure "+relLayTwo.getHeight() );
}
When a View is first created, it's width and height are not available to you until onMeasure() has been called. Due to this, the first time you try to get the values, they have not been assigned yet.
Since you're using a custom View, the solution is pretty simple. Simply move the code that gets the height and width into onMeasure() and use it after that.
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
width = getWidth(); // Get View Width
height = getHeight();// Get View Height
}
Here's how i got solution for this problem.
the actual problem with getting layout's height when we set it to wrap content is, it will not give height until it will actually draw on a screen. and in my case the custom layout got called first and then it will call remaining layout, so there is not a chance for layout to get draw.
so what i did is i got actual height and width of the screen run time by using following code.
DisplayMetrics metrics = new DisplayMetrics();
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(metrics);
height = metrics.heightPixels;
width = metrics.widthPixels;
and after i got screens height and width, inflate view.
after that got linearlayouts height and add new height to it using following code.
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) relLayTwo.getLayoutParams();
Log.d("test", "height "+params.height);
params.height = height*40/100;
relLayTwo.setLayoutParams(params);
relLayTwo.setVisibility(View.GONE);
and its worked!!
simply use this to get the height and width of which visibility is GONE..
myView.getMeasuredHeight();
myView.getMeasuredWidth();
<RelativeLayout
android:id="#+id/relLayTwo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/btnNEWCLICK"
android:background="#000"
android:visibility="gone" > //don't put gone in xml
In OnViewCreated look for the height and after that make this view GONE
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
relLayTwo = (RelativeLayout) findViewById(R.id.relLayTwo);
mHeight = relLayTwo.getHeight();
relLayTwo.setVisibility(View.GONE);}
In this way you will get the height because on onViewCreated the view is already drawn, and after you have what you need, make the view GONE.

Android View Animation

i've been scrounging the internet for a while now and have been unable to find s viable solution for my animation problem.
I have a list view where when you click on one of the items, more information animates from the bottom to give you a few lines of additional information. That is simply a linearlayout that i have inside the XML file im using for these list items, here:
<?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="wrap_content" >
<LinearLayout
android:id="#+id/friendActivityList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/friendInfo"
android:background="#color/grey"
android:orientation="vertical"
android:visibility="gone" >
<RelativeLayout
android:id="#+id/RelativeLayout04"
android:layout_width="match_parent"
android:layout_height="#dimen/freind_activity_list_height" >
<ImageView
android:id="#+id/ImageView04"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView04"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout03"
android:layout_width="match_parent"
android:layout_height="#dimen/freind_activity_list_height" >
<ImageView
android:id="#+id/ImageView03"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView03"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout02"
android:layout_width="match_parent"
android:layout_height="#dimen/freind_activity_list_height" >
<ImageView
android:id="#+id/ImageView02"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView02"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="#dimen/freind_activity_list_height" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/imageView1"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="match_parent"
android:layout_height="#dimen/freind_activity_list_height">
<ImageView
android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_margin="5dp"
android:src="#drawable/logo_d" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/ImageView01"
android:text="TextView"
android:textColor="#color/black"
android:textSize="17dp" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/friendInfo"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:background="#drawable/bg_list_item_n" >
<ImageView android:id="#+id/imgCompany"
android:layout_marginLeft="5dp"
android:layout_centerVertical="true"
android:layout_width="60dp"
android:src="#drawable/ic_launcher"
android:scaleType="centerInside"
android:layout_alignParentLeft="true"
android:layout_height="50dp">
</ImageView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_toRightOf="#id/imgCompany"
android:background="#android:color/transparent"
android:gravity="left|center"
android:orientation="vertical"
android:paddingLeft="5dp" >
<TextView android:id="#+id/lblCompanyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="13dp"
android:text="Company Name">
</TextView>
<TextView android:id="#+id/lblReawrdDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textSize="13dp"
android:text="Reawrd Description">
</TextView>
<TextView android:id="#+id/lblScores"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textSize="13dp"
android:singleLine="true"
android:text="My Score: 13434 | Top Score: 344425">
</TextView>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Most of this is just place holder information so that i can get the animation to work correctly. Here is the code that im using for the animation:
listviewFriends.setOnItemClickListener(new OnItemClickListener() {//this is the listView that im animating inside of
public void onItemClick(AdapterView<?> parent, View view,final int pos, long id) {
Log.v("ListItemClicked", "this position was clicked: "+pos);
if(friendInfoList != null){
friendInfoList.clearAnimation();//this is the new view that gets animated and is supposed to push everything below it out of the way
friendInfoList.setVisibility(View.GONE);
}
friendInfoList = (LinearLayout) view.findViewById(R.id.friendActivityList);
friendInfoList.setVisibility(View.VISIBLE);
friendInfoList.startAnimation(infoAnim);
}
});
infoAnim = new TranslateAnimation(0,0, -150, 0);//this is the animation im using
infoAnim.setDuration(1000);
infoAnim.setFillAfter(true);
No the result of this is that when i click on the list view item the entire space that the supposed-to-be-animated view takes up at the end is white while the view animates from the top down. The location is correct, but i want it to animate and push everything below it out of the way, instead it instantly pushes everything out of the way then animates to fill that space.
Any idea how i can get it to push everything out of the way during the animation instead of immediately? Is it even possible to achieve this effect? any help is greatly appreciated.
Also, I know how i can make it simply animate ontop of the other views, but i need it to actually push everything out of the way.
The trick with this is to create your own Animation subclass.
public class ExpandAnimation extends Animation
{
private int _targetHeight;
private View _view;
private boolean _down;
public ExpandAnimation(View view, int targetHeight)
{
_view = view;
_targetHeight = targetHeight;
}
#Override
protected void applyTransformation(float interpolatedTime, Transformation t)
{
int newHeight;
if(_down)
{
newHeight = (int) (_targetHeight * interpolatedTime);
}
else
{
newHeight = (int) (_targetHeight * (1 - interpolatedTime));
}
_view.getLayoutParams().height = newHeight;
_view.requestLayout();
}
public ExpandAnimation expand()
{
_down = true;
return this;
}
public ExpandAnimation collapse()
{
_down = false;
return this;
}
#Override
public void initialize(int width, int height, int parentWidth, int parentHeight)
{
super.initialize(width, height, parentWidth, parentHeight);
}
#Override
public boolean willChangeBounds()
{
return true;
}
}
Then you can apply that to your view that should expand:
public void togglePreview()
{
if(_expanded) _preview.startAnimation(_animation.collapse());
else _preview.startAnimation(_animation.expand());
_expanded = !_expanded;
getParent().requestLayout();
}

Categories

Resources