我有一个包含多个textview的水平列表视图。我想将这些文本视图(项目)仅从右到左翻译(动画)为循环方式,同时单击按钮。不翻译水平列表视图布局。这可能吗?
编辑:
对于这个水平列表视图,我使用适配器将值加载到该列表中。
像这样:
private static String[] dataObjects = new String[]{ "Text #1",
"Text #2",
"Text #3","Text #4","Text #5","Text #6","Text #7","Text #8","Text #9","Text #10" };
private BaseAdapter mAdapter = new BaseAdapter() {
@Override
public int getCount() {
return dataObjects.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@SuppressLint({ "ViewHolder", "InflateParams" })
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View retval = LayoutInflater.from(parent.getContext()).inflate(R.layout.viewitem, null);
TextView title = (TextView) retval.findViewById(R.id.title);
//Button button = (Button) retval.findViewById(R.id.clickbutton);
//button.setOnClickListener(mOnButtonClicked);
title.setText(dataObjects[position]);
return retval;
}
};
并将此适配器设置为水平列表视图:
listView=(HorizontalListView)findViewById(R.id.simple_list);
listView.setAdapter(mAdapter);
提前致谢...
答案 0 :(得分:0)
在res中创建translate.xml - >动画目录。代码:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:duration="500"
android:fillAfter="true"
android:fromXDelta="100%"
android:toXDelta="0%" >
/>
更改android:fromXDelta="100%" android:toXDelta="0%"
中的百分比以满足您的需求。现在使用:
animationT = AnimationUtils.loadAnimation(myContext,
R.anim.translate);
//put inside your clickListener
button.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick(View v) {
textView1.startAnimation(animationT);
textView2.startAnimation(animationT);
textView3.startAnimation(animationT);
});