【发布时间】:2017-03-04 02:42:37
【问题描述】:
我创建了一个自定义布局以进入列表视图。我在自定义布局中有一个动画,但我无法显示它。如果我将其从自定义列表视图中取出,动画将起作用,但它显然不在列表视图中!
下面的代码 sn-ps 准确地显示了我所调用的内容。我相信错误在于我使用 LayoutInflator 的方式,但我不确定发生了什么。
活动:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayAdapter<Group> adapter = new ArrayAdapter<Group>(this, custom_listview_activetethers, R.id.label, currentUser.getGroupList());
setListAdapter(adapter);
setContentView(R.layout.activity_tether_list);
//standard animated image in the layout, works fine but obviously not in the listview
ImageView mImageViewEmptying = (ImageView) findViewById(R.id.tetherPulseAnimationTest);
((AnimationDrawable) mImageViewEmptying.getBackground()).start();
//custom animated image, does not show
LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.custom_listview_activetethers, null);
ImageView mImageViewFilling = (ImageView) dialogView.findViewById(R.id.tetherPulseAnimation);
((AnimationDrawable) mImageViewFilling.getBackground()).start();
布局(包含动画的工作示例):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_tether_list"
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="uk.tether.topcom.tether.TetherListActivity">
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="30dp"
android:layout_marginBottom="10dp"/>
<ImageView
android:id="@+id/tetherPulseAnimationTest"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="4px"
android:background="@drawable/tetheredanimation"
/>
</RelativeLayout>
自定义布局(唯一不显示的是动画):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/profilepic"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="4px"
android:layout_marginRight="2px"
android:layout_marginTop="4px"
android:src="@drawable/tetherlogo" >
</ImageView>
<TextView
android:id="@+id/label"
android:layout_width="257dp"
android:layout_height="60dp"
android:text="@+id/label"
android:layout_marginTop="4px"
android:textSize="15dp"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:gravity="center">
</TextView>
<ImageView
android:id="@+id/tetherPulseAnimation"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="4px"
android:background="@drawable/tetheredanimation"
/>
</LinearLayout>
我花了相当多的时间试图让它工作,但仍然没有运气!我认为膨胀和检索视图,然后从该视图调用动画会起作用,但它没有。
谁能看到我哪里出错了,因为我感觉很迷茫!
编辑: 外观示例,显示自定义布局的工作元素以及动画应为红色的位置。还显示了在左上角工作的非自定义动画,以排除图像等问题。
【问题讨论】:
标签: android android-layout listview android-activity view