如何创建可扩展的视图,而不使用android中的任何库
问题描述:
我正在创建一个应用程序,在该应用程序中我的设计中有一个可扩展的视图。事情是我可以使用Expandable listView或任何其他库创建它。但我需要做到这一点,而无需listView或库。有没有解决方案?我需要创建的视图如下 - 如何创建可扩展的视图,而不使用android中的任何库
因此,如果不使用库和listView,我该怎么做?
答
按照您的要求,你需要做的,甚至没有列表视图,我想你不想适配器过这样你就可以在你的主要活动 //内活动试试这个
TextView txt_help_gest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info);
txt_help_gest = (TextView) findViewById(R.id.txt_help_gest);
// hide until its title is clicked
txt_help_gest.setVisibility(View.GONE);
}
> /**
> * onClick handler
> */
public void toggle_contents(View v){
txt_help_gest.setVisibility(txt_help_gest.isShown()
? View.GONE
: View.VISIBLE);
}
一段动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<scale
android:duration="200"
android:fromXScale="1.0"
android:fromYScale="0.0"
android:interpolator="@android:anim/linear_interpolator"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
Java代码
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
//...
/**
*
* @param ctx
* @param v
*/
public static void slide_down(Context ctx, View v){
Animation a = AnimationUtils.loadAnimation(ctx, R.anim.slide_down);
if(a != null){
a.reset();
if(v != null){
v.clearAnimation();
v.startAnimation(a);
}
}
}
/** * 上单击主要活动处理 */
public void toggle_contents(View v){
if(txt_help_gest.isShown()){
Fx.slide_up(this, txt_help_gest);
txt_help_gest.setVisibility(View.GONE);
}
else{
txt_help_gest.setVisibility(View.VISIBLE);
Fx.slide_down(this, txt_help_gest);
}
}