<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="#FFFFFF"
android:orientation="vertical"
android:padding="6dp" >
<LinearLayout
android:id="@+id/part2_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/part2_iv_icon0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/safeicon0" />
<ImageView
android:id="@+id/part2_iv_icon1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:src="@drawable/safeicon0" />
<ImageView
android:id="@+id/part2_iv_icon2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:src="@drawable/safeicon0" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<ImageView
android:id="@+id/part2_iv_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow_down" />
</LinearLayout>
<LinearLayout
android:id="@+id/part2_ll_texts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/part2_ll_text_0"
style="@style/Text_Detail"
android:layout_margin="2dp"
android:drawableLeft="@drawable/safedesurl0"
android:text="正版xxxxxxxxxxxx" />
<TextView
android:id="@+id/part2_ll_text_1"
style="@style/Text_Detail"
android:layout_margin="2dp"
android:drawableLeft="@drawable/safedesurl0"
android:text="正版xxxxxxxxxxxx" />
<TextView
android:id="@+id/part2_ll_text_2"
style="@style/Text_Detail"
android:layout_margin="2dp"
android:drawableLeft="@drawable/safedesurl0"
android:text="正版xxxxxxxxxxxx" />
</LinearLayout>
</LinearLayout>
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.include_app_detail_part2);
final LinearLayout part2_ll = (LinearLayout) findViewById(R.id.part2_ll);
final ImageView part2_iv_arrow = (ImageView) findViewById(R.id.part2_iv_arrow);
final LinearLayout part2_ll_texts = (LinearLayout) findViewById(R.id.part2_ll_texts);
CollapseUtil.initCollapseAnim(part2_ll,part2_iv_arrow,part2_ll_texts);
}
}
**
*伸缩工具类
*/
public class CollapseUtil {
public static void initCollapseAnim(final LinearLayout bar, final ImageView arrowIv, final LinearLayout collapseView) {
final int collapseHeight = 0;
;
collapseView.measure(0, 0);
final int expandHeight = collapseView.getMeasuredHeight();
collapseView.getLayoutParams().height = collapseHeight;
arrowIv.setImageResource(R.drawable.arrow_down);
collapseView.requestLayout();
bar.setOnClickListener(new View.OnClickListener() {
private boolean collapse = true;
@Override
public void onClick(View v) {
if (collapse) {
collapse = false;
arrowIv.setImageResource(R.drawable.arrow_up);
} else {
collapse = true;
arrowIv.setImageResource(R.drawable.arrow_down);
}
int fromHeight = 0;
int toHeigith = 0;
fromHeight = collapse ? expandHeight : collapseHeight;
toHeigith = collapse ? collapseHeight : expandHeight;
ValueAnimator valueAnimator = ValueAnimator.ofInt(fromHeight, toHeigith);
valueAnimator.setDuration(500);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Integer newHeight = (Integer) animation.getAnimatedValue();
collapseView.getLayoutParams().height = newHeight;
collapseView.requestLayout();
}
});
valueAnimator.start();
}
});
}
}