my application have 2 fragments:
1 - Have several fields to insert info for a query, and initially it shows only a field to input the name and a button that make it grows;
2 - A list view that would show the results for the query.
I'm using Visibility.GONE to make the trick (not show the other fields, and when the user press the button, they appear):
I have several of these
<android.support.v7.widget.LinearLayoutCompat
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.tcgapp.myrium.fowhelper.MainActivity"
tools:showIn="#layout/activity_main"
android:orientation="vertical"
android:id="#+id/fragment_search_area"
>
<!--android:background="#c94040" -->
<!-- Name of Card and button to expand the view-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:id="#+id/layout_name_search"
android:background="#android:color/darker_gray">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/label_name"
android:text="#string/name_label"
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textStyle="bold"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text_name"
android:hint="#string/name_hint"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:singleLine="true"
android:layout_weight="0.90" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button_expand"
android:src="#drawable/ic_arrow_downward_black_24dp" />
</LinearLayout>
<!-- Type Set and Format-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/search_tags_area"
android:orientation="horizontal"
android:background="#android:color/holo_blue_dark">
<Spinner
android:id="#+id/spinner_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<util.MultiSpinner
android:id="#+id/spinner_rarity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<util.MultiSpinner
android:id="#+id/spinner_set"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<Spinner
android:id="#+id/spinner_format"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
</LinearLayout>
<!-- Card Text Field-->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edit_card_text"
android:hint="#string/field_text"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<!-- Spinners-->
<!-- Attribute and choices-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:id="#+id/layout_attribute"
android:background="#android:color/darker_gray"
android:visibility="gone">
<util.MultiSpinner
android:id="#+id/multi_spinner_attribute"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
<Spinner
android:id="#+id/spinner_choices_to_query_attribute"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"/>
</LinearLayout>
<!-- Now the query fields-->
<!-- Atk Def-->
<LinearLayout
android:id="#+id/layout_atkdef"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#75b194"
>
<TextView
android:id="#+id/text_atk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/field_atk"
android:gravity="left"
android:textStyle="bold"
android:layout_weight="2"
android:textSize="15sp"
android:paddingLeft="10dp"/>
<Spinner
android:id="#+id/spinner_atk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<android.support.v7.widget.AppCompatEditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:inputType="numberSigned"/>
<!-- Atk field-->
<TextView
android:id="#+id/text_def"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/field_def"
android:gravity="left"
android:textStyle="bold"
android:layout_weight="2"
android:textSize="15sp"
android:paddingLeft="10dp"
/>
<Spinner
android:id="#+id/spinner_def"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<android.support.v7.widget.AppCompatEditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:inputType="numberSigned"/>
</LinearLayout>
<!-- SubType and CMC-->
<LinearLayout
android:id="#+id/layout_subtype_cmc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:background="#75b194"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/field_subtype"
android:layout_weight="2"
android:textSize="15sp"
android:paddingLeft="10dp"
android:textStyle="bold"/>
<android.support.v7.widget.AppCompatEditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_weight="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/field_cmc"
android:layout_weight="1"
android:textSize="15sp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textStyle="bold"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/spinner_cmc"/>
</LinearLayout>
<!-- Card Flavor e Code-->
<LinearLayout
android:id="#+id/layout_flavor_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:background="#75b194"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/edit_card_flavor"
android:hint="#string/field_flavor"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_weight="1"
android:singleLine="true"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/edit_card_code"
android:hint="#string/field_code"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_weight="1"
android:singleLine="true"/>
</LinearLayout>
And on Java code, i have an animator object, and this is its AnimationEnd():
#Override
public void onClick(View v) {
int newWeight = isExpanded ? 0 : 60;
ViewWeightAnimationWrapper animationWrapper = new ViewWeightAnimationWrapper(getView());
ObjectAnimator anim = ObjectAnimator.ofFloat(animationWrapper,
"weight",
animationWrapper.getWeight(),
newWeight);
anim.setDuration(500);
anim.addListener(new AnimatorListenerAdapter() {
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
// if (!isExpanded){
// getView().findViewById(R.id.layout_atkdef).setVisibility(View.INVISIBLE);
// getView().findViewById(R.id.layout_subtype_cmc).setVisibility(View.INVISIBLE);
// getView().findViewById(R.id.layout_attribute).setVisibility(View.INVISIBLE);
// getView().findViewById(R.id.layout_flavor_code).setVisibility(View.INVISIBLE);
// }
}
#Override
public void onAnimationEnd (Animator animation){
super.onAnimationEnd(animation);
if (isExpanded) {
imageButtonToggle.setImageResource(R.drawable.ic_arrow_downward_black_24dp);
getView().findViewById(R.id.layout_atkdef).setVisibility(View.GONE);
getView().findViewById(R.id.layout_subtype_cmc).setVisibility(View.GONE);
getView().findViewById(R.id.layout_attribute).setVisibility(View.GONE);
getView().findViewById(R.id.layout_flavor_code).setVisibility(View.GONE);
} else {
imageButtonToggle.setImageResource(R.drawable.ic_arrow_upward_black_24dp);
getView().findViewById(R.id.layout_atkdef).setVisibility(View.VISIBLE);
getView().findViewById(R.id.layout_subtype_cmc).setVisibility(View.VISIBLE);
getView().findViewById(R.id.layout_attribute).setVisibility(View.VISIBLE);
getView().findViewById(R.id.layout_flavor_code).setVisibility(View.VISIBLE);
}
isExpanded = !isExpanded;
}
}
);
anim.start();
}
}
This is the way to hide the fields and show only when the user presses the expand button, or is a better way?
UPDATE: Providing full code.
Assuming you're asking if there's a nicer way of expanding/hiding an area with input, I'll share my implementation using your variables as best I can. I'll make some necessary notes as well.
//consider changing imageButtonToggle to a container view with an image in it
//in this example I'll use carrotImage as the image contained within imageButtonToggle
//formContainer contains all the views you're toggling from GONE to VISIBLE.
imageButtonToggle.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (!isExpanded) {
ViewAnimationHelper
.expand(formContainer, 300, false);
} else {
ViewAnimationHelper.collapse(formContainer, 300);
}
carrotImage.animate().rotation(ROTATION_COUNT);
ROTATION_COUNT += 180f;
//Silly check.. but better safe than sorry.
if (ROTATION_COUNT >= Float.MAX_VALUE)
ROTATION_COUNT = 0f;
isExpanded= !isExpanded;
}
});
public class ViewAnimationHelper {
/**
* Easy way to expand a given view after measuring with
* v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
*
* #param v
* #param duration
*/
public static void expand(final View v, int duration,
boolean bStartFromZeroHeight) {
v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
final int targetHeight = v.getMeasuredHeight();
if (bStartFromZeroHeight)
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) (targetHeight * interpolatedTime);
v.requestLayout();
}
#Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setDuration(duration);
v.startAnimation(a);
}
/**
* Easy way to just collapse any given view and any given speed
*
* #param v
* #param duration
*/
public static void collapse(final View v, int duration) {
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;
}
};
// 1dp/ms
a.setDuration(duration);
v.startAnimation(a);
}
}
Related
I'm trying to implement and expandable CardView, but I'm having proplems
heres my xml file for the cardview:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:clickable="true"
android:elevation="5dp"
android:foreground="?android:attr/selectableItemBackground"
android:orientation="vertical"
android:stateListAnimator="#drawable/cardview_lift_on_touch">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/product_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="#drawable/default_network_image"/>
<TextView
android:id="#+id/product_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingTop="24dp"
android:text="Product Name"
android:textColor="#000000"
android:textSize="24dp"
android:textStyle="bold" />
<TextView
android:id="#+id/product_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="A buyer persona is an imaginary customer. It is the person for whom you've developed your product and to whom you'd love to sell it (of course!). He or she represents your target audience, but is much more real than a vague description of some demographics."
android:textColor="#000000"
android:textSize="14dp"
android:visibility="visible" />
<TextView
android:id="#+id/product_url"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="24dp"
android:paddingLeft="16dp"
android:text="example.syriatel.sy/akrab_eleik"
android:textColor="#0048ff"
android:textSize="14dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
I'm trying to expand the "product description" TextView when the CardView is clicked by passing it to the following method:
public static void expand(final View v) {
final int initialHeight = v.getHeight();
v.measure(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
final int targetHeight = v.getMeasuredHeight();
v.getLayoutParams().height = 1;
v.setVisibility(View.VISIBLE);
Animation a = new Animation() {
#Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
v.getLayoutParams().height = interpolatedTime == 1
? LinearLayout.LayoutParams.WRAP_CONTENT
: (int) (targetHeight * interpolatedTime);
v.requestLayout();
}
#Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setDuration((int) ((initialHeight / v.getContext().getResources().getDisplayMetrics().density))/10);
v.startAnimation(a);
}
The resulting animation is initially smooth but suddenly expands the view to full hight at the end
I got the code I'm using from this answer:
https://stackoverflow.com/a/13381228/5716823
Reading the comments didn't help.
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.
I have a problem with a button , if add him background my animation stop work.
Here is xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#drawable/coinsbackground" >
<LinearLayout
android:id="#+id/instructiuni"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/instructiuneinceput" />
<TextView
android:id="#+id/instructiuniInceputHtml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:background="#8CFAFAFA" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/terminareinceput" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/intructiuni" />
<TextView
android:id="#+id/instructiuniHtml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:background="#8CFAFAFA" />
<Button
android:id="#+id/back_instructiuni"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back >>"
android:background="#5B52D7" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/menuButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:layout_weight="1" >
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:layout_weight="18" >
<Button
android:id="#+id/playgame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Play"
android:textStyle="bold" />
<Button
android:id="#+id/instructions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Instructions"
android:textStyle="bold" />
<Button
android:id="#+id/settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Settings"
android:textStyle="bold"
android:background="#5B52D7" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:layout_weight="1" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
My animation class:
public class FlipWidthAnimation extends Animation {
private int startWidth;
private int deltaWidth; // distance between start and end height
private View view;
/**
* constructor, do not forget to use the setParams(int, int) method before
* starting the animation
* #param v
*/
public FlipWidthAnimation(View v) {
this.view = v;
}
#Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
view.getLayoutParams().width = (int) (startWidth + deltaWidth * interpolatedTime);
view.requestLayout();
}
/**
* set the starting and ending height for the resize animation
* starting height is usually the views current height, the end height is the height
* we want to reach after the animation is completed
* #param start height in pixels
* #param end height in pixels
*/
public void setParams(int start, int end) {
this.startWidth = start;
deltaWidth = end - startWidth;
}
/**
* set the duration for the hideshowanimation
*/
#Override
public void setDuration(long durationMillis) {
super.setDuration(durationMillis);
}
#Override
public boolean willChangeBounds() {
return true;
}
}
and here event:
if(v.getId() == R.id.instructions){
LinearLayout instructiuni = (LinearLayout)findViewById(R.id.instructiuni);
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) instructiuni.getLayoutParams();
FlipWidthAnimation a = new FlipWidthAnimation(instructiuni);
a.setDuration(1000);
a.setParams(lp.width, getWindowManager().getDefaultDisplay().getWidth());
instructiuni.startAnimation(a);
}
he come in event is not a problem i debuged i see no error , but animation not started , but for example if click on settings animation started if was presset instructions before press settings. realy have no ideea why .
Solution was to give invalidate() my button: here is link who help me
I'm doing a layout a bit complex, just that I can't fix the error that is indicated by LINT (...has blackberries than 80 views, bad for performance)
This is the layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".Activity_schedapunti">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:gravity="center_horizontal"
android:text="#string/esame_visivo"
android:textColor="#android:color/white"
android:textStyle="bold"
android:background="#android:color/black"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:gravity="center_horizontal"
android:text="#string/punteggio_parziale"
android:textColor="#android:color/white"
android:textStyle="bold"
android:background="#android:color/black"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:orientation="horizontal">
<TextView
android:id="#+id/textview_aspetto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/aspetto"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coeff_x1"
android:textStyle="bold"
android:textColor="#color/light_yellow"/>
<EditText
android:id="#+id/edittext_aspetto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
<TextView
android:id="#+id/textview_puteggio_parziale_aspetto"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight=".3"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:orientation="horizontal">
<TextView
android:id="#+id/textview_punti_colore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/colore"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coeff_x2"
android:textStyle="bold"
android:textColor="#color/light_yellow"/>
<EditText
android:id="#+id/edittext_punti_colore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
<TextView
android:id="#+id/textview_puteggio_parziale_colore"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight=".3"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:gravity="center_horizontal"
android:text="#string/esame_olfattivo"
android:textColor="#android:color/white"
android:textStyle="bold"
android:background="#android:color/black"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:gravity="center_horizontal"
android:text="#string/punteggio_parziale"
android:textColor="#android:color/white"
android:textStyle="bold"
android:background="#android:color/black"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:orientation="horizontal">
<TextView
android:id="#+id/textview_punti_intensita"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/intensita"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coeff_x1"
android:textStyle="bold"
android:textColor="#color/light_yellow"/>
<EditText
android:id="#+id/edittext_punti_intensita"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
<TextView
android:id="#+id/textview_puteggio_parziale_intensita"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight=".3"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:orientation="horizontal">
<TextView
android:id="#+id/textview_punti_complessita"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/complessita"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coeff_x2"
android:textStyle="bold"
android:textColor="#color/light_yellow"/>
<EditText
android:id="#+id/edittext_punti_complessita"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
<TextView
android:id="#+id/textview_puteggio_parziale_complessita"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight=".3"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:orientation="horizontal">
<TextView
android:id="#+id/textview_punti_qualita"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/qualita"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coeff_x3"
android:textStyle="bold"
android:textColor="#color/light_yellow"/>
<EditText
android:id="#+id/edittext_punti_qualita"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
<TextView
android:id="#+id/textview_puteggio_parziale_qualita"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight=".3"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:gravity="center_horizontal"
android:text="#string/esame_gusto_olfattivo"
android:textColor="#android:color/white"
android:textStyle="bold"
android:background="#android:color/black"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:gravity="center_horizontal"
android:text="#string/punteggio_parziale"
android:textColor="#android:color/white"
android:textStyle="bold"
android:background="#android:color/black"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:orientation="horizontal">
<TextView
android:id="#+id/textview_punti_struttura"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/struttura"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coeff_x1"
android:textStyle="bold"
android:textColor="#color/light_yellow"/>
<EditText
android:id="#+id/edittext_punti_struttura"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
<TextView
android:id="#+id/textview_puteggio_parziale_struttura"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight=".3"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:orientation="horizontal">
<TextView
android:id="#+id/textview_punti_equilibrio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/equilibrio"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coeff_x1"
android:textStyle="bold"
android:textColor="#color/light_yellow"/>
<EditText
android:id="#+id/edittext_punti_equilibrio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
<TextView
android:id="#+id/textview_puteggio_parziale_equilibrio"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight=".3"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:orientation="horizontal">
<TextView
android:id="#+id/textview_punti_intensita_gusto_olfattivo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/intensita"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coeff_x1"
android:textStyle="bold"
android:textColor="#color/light_yellow"/>
<EditText
android:id="#+id/edittext_punti_intensita_gusto_olfattivo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
<TextView
android:id="#+id/textview_puteggio_parziale_intensita_gusto_olfattivo"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight=".3"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:orientation="horizontal">
<TextView
android:id="#+id/textview_punti_persistenza"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/persistenza"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coeff_x2"
android:textStyle="bold"
android:textColor="#color/light_yellow"/>
<EditText
android:id="#+id/edittext_punti_persistenza"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
<TextView
android:id="#+id/textview_puteggio_parziale_persistenza"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight=".3"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:orientation="horizontal">
<TextView
android:id="#+id/textview_punti_qualita_gusto_olfattivo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/qualita"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coeff_x3"
android:textStyle="bold"
android:textColor="#color/light_yellow"/>
<EditText
android:id="#+id/edittext_punti_qualita_gusto_olfattivo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
<TextView
android:id="#+id/textview_puteggio_parziale_qualita_gusto_olfattivo"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight=".3"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:orientation="horizontal">
<TextView
android:id="#+id/textview_punti_armonia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/armonia"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/coeff_x3"
android:textStyle="bold"
android:textColor="#color/light_yellow"/>
<EditText
android:id="#+id/edittext_punti_armonia"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:inputType="number"
android:singleLine="true" />
</LinearLayout>
<TextView
android:id="#+id/textview_puteggio_parziale_armonia"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight=".3"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:gravity="center_horizontal"
android:text="#string/punteggio_totale"
android:textColor="#android:color/white"
android:textStyle="bold"
android:background="#android:color/black"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".3"
android:gravity="center_horizontal"
android:textColor="#color/light_yellow"
android:textStyle="bold"
android:background="#android:color/black"/>
</TableRow>
</TableLayout>
</ScrollView>
I read to use a ListView, but how should I to do? Not all the rows are equal, or in any case there are some elements in the middle which are not equal to all other rows!
Image:
This definitely looks like a good candidate for a ListView. As I stated in my comment, you can use a custom layout in your Adapter. I don't know how you are getting your data for it so I can't say exactly how to check but in each round of getView() you can check the data and decide which Views to show/hide.
Simply create the layout with the TextViews, etc... that each row might need, looks like probably inside of a vertical LinearLayout with horizontal LinearLayouts inside or just a RelativeLayout then change visibility to visible/gone depending on what you need.
If you are unfamiliar with doing this then you can see this tutorial on doing it.
Adapter Docs
ListView Docs
As pointed out in a comment, you could inflate different layouts in your getView() method of your Adapter if you have very different layouts which may make toggling visibility a bad approach. This just depends on your data and layouts.
you must use a MergeAdapter where you can merge differents adapter to only one. For example titles and values. I got the code from StackOverflow but i can't find the topic so i paste here the code that i found.
package com.mydocum.adapters;
import java.util.ArrayList;
import android.database.DataSetObserver;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.SectionIndexer;
import android.widget.TextView;
/**
* Adapter that merges multiple child adapters and views into a single
* contiguous whole.
*
* Adapters used as pieces within MergeAdapter must have view type IDs
* monotonically increasing from 0. Ideally, adapters also have distinct ranges
* for their row ids, as returned by getItemId().
*
*/
public class MergeAdapter extends BaseAdapter implements SectionIndexer {
protected ArrayList<ListAdapter> pieces = new ArrayList<ListAdapter>();
protected String noItemsText;
/**
* Stock constructor, simply chaining to the superclass.
*/
public MergeAdapter() {
super();
}
/**
* Adds a new adapter to the roster of things to appear in the aggregate
* list.
*
* #param adapter
* Source for row views for this section
*/
public void addAdapter(ListAdapter adapter) {
pieces.add(adapter);
adapter.registerDataSetObserver(new CascadeDataSetObserver());
}
/**
* Get the data item associated with the specified position in the data set.
*
* #param position
* Position of the item whose data we want
*/
public Object getItem(int position) {
for (ListAdapter piece : pieces) {
int size = piece.getCount();
if (position < size) {
return (piece.getItem(position));
}
position -= size;
}
return (null);
}
public void setNoItemsText(String text){
noItemsText = text;
}
/**
* Get the adapter associated with the specified position in the data set.
*
* #param position
* Position of the item whose adapter we want
*/
public ListAdapter getAdapter(int position) {
for (ListAdapter piece : pieces) {
int size = piece.getCount();
if (position < size) {
return (piece);
}
position -= size;
}
return (null);
}
/**
* How many items are in the data set represented by this Adapter.
*/
public int getCount() {
int total = 0;
for (ListAdapter piece : pieces) {
total += piece.getCount();
}
if(total == 0 && noItemsText != null){
total = 1;
}
return (total);
}
/**
* Returns the number of types of Views that will be created by getView().
*/
#Override
public int getViewTypeCount() {
int total = 0;
for (ListAdapter piece : pieces) {
total += piece.getViewTypeCount();
}
return (Math.max(total, 1)); // needed for setListAdapter() before
// content add'
}
/**
* Get the type of View that will be created by getView() for the specified
* item.
*
* #param position
* Position of the item whose data we want
*/
#Override
public int getItemViewType(int position) {
int typeOffset = 0;
int result = -1;
for (ListAdapter piece : pieces) {
int size = piece.getCount();
if (position < size) {
result = typeOffset + piece.getItemViewType(position);
break;
}
position -= size;
typeOffset += piece.getViewTypeCount();
}
return (result);
}
/**
* Are all items in this ListAdapter enabled? If yes it means all items are
* selectable and clickable.
*/
#Override
public boolean areAllItemsEnabled() {
return (false);
}
/**
* Returns true if the item at the specified position is not a separator.
*
* #param position
* Position of the item whose data we want
*/
#Override
public boolean isEnabled(int position) {
for (ListAdapter piece : pieces) {
int size = piece.getCount();
if (position < size) {
return (piece.isEnabled(position));
}
position -= size;
}
return (false);
}
/**
* Get a View that displays the data at the specified position in the data
* set.
*
* #param position
* Position of the item whose data we want
* #param convertView
* View to recycle, if not null
* #param parent
* ViewGroup containing the returned View
*/
public View getView(int position, View convertView, ViewGroup parent) {
for (ListAdapter piece : pieces) {
int size = piece.getCount();
if (position < size) {
return (piece.getView(position, convertView, parent));
}
position -= size;
}
if(noItemsText != null){
TextView text = new TextView(parent.getContext());
text.setText(noItemsText);
return text;
}
return (null);
}
/**
* Get the row id associated with the specified position in the list.
*
* #param position
* Position of the item whose data we want
*/
public long getItemId(int position) {
for (ListAdapter piece : pieces) {
int size = piece.getCount();
if (position < size) {
return (piece.getItemId(position));
}
position -= size;
}
return (-1);
}
public int getPositionForSection(int section) {
int position = 0;
for (ListAdapter piece : pieces) {
if (piece instanceof SectionIndexer) {
Object[] sections = ((SectionIndexer) piece).getSections();
int numSections = 0;
if (sections != null) {
numSections = sections.length;
}
if (section < numSections) {
return (position + ((SectionIndexer) piece)
.getPositionForSection(section));
} else if (sections != null) {
section -= numSections;
}
}
position += piece.getCount();
}
return (0);
}
public int getSectionForPosition(int position) {
int section = 0;
for (ListAdapter piece : pieces) {
int size = piece.getCount();
if (position < size) {
if (piece instanceof SectionIndexer) {
return (section + ((SectionIndexer) piece)
.getSectionForPosition(position));
}
return (0);
} else {
if (piece instanceof SectionIndexer) {
Object[] sections = ((SectionIndexer) piece).getSections();
if (sections != null) {
section += sections.length;
}
}
}
position -= size;
}
return (0);
}
public Object[] getSections() {
ArrayList<Object> sections = new ArrayList<Object>();
for (ListAdapter piece : pieces) {
if (piece instanceof SectionIndexer) {
Object[] curSections = ((SectionIndexer) piece).getSections();
if (curSections != null) {
for (Object section : curSections) {
sections.add(section);
}
}
}
}
if (sections.size() == 0) {
return (null);
}
return (sections.toArray(new Object[0]));
}
private class CascadeDataSetObserver extends DataSetObserver {
#Override
public void onChanged() {
notifyDataSetChanged();
}
#Override
public void onInvalidated() {
notifyDataSetInvalidated();
}
}
}
Here how you need to use it:
MergeAdapter adapter = new MergeAdapter();
AdapterA adapterA = new AdapterA(...);
AdapterB adapterB = new AdapterB(...);
adapter.addAdapter(adapterA);
adapter.addAdapter(adapterB);
listview.setAdapter(adapter);
In the listview you will have the adapterA and andapterB one after other and shower correcly. The two adapter can have diffente object.
Bye.
Wow this is bad, use a ListView instead of a TableView and dynamically add rows based on what section you are in.
I would extend BaseAdapter to achieve this
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();
}