Android 滚动时线性布局可见性不一致
我是java新手,我有一个从设备库获取媒体的插件,我有一个Android 滚动时线性布局可见性不一致,android,cordova,webview,visibility,Android,Cordova,Webview,Visibility,我是java新手,我有一个从设备库获取媒体的插件,我有一个LinearLayout,其中包含一个TextView,用于显示库中视频的持续时间。但是,我看到一些不寻常的行为,如果图像显示在先前包含视频缩略图的网格正方形中,则持续时间会错误地应用于图像。默认情况下,LinearLayout的可见性设置为GONE,如果是视频缩略图,则更改为VISIBLE。以下是相关的代码片段: // view.xml <?xml version="1.0" encoding="ut
LinearLayout
,其中包含一个TextView
,用于显示库中视频的持续时间。但是,我看到一些不寻常的行为,如果图像显示在先前包含视频缩略图的网格正方形中,则持续时间会错误地应用于图像。默认情况下,LinearLayout
的可见性设置为GONE
,如果是视频缩略图,则更改为VISIBLE
。以下是相关的代码片段:
// view.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DDDDDD"
android:layout_margin="2dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:id="@+id/vImage"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#80000000"
android:orientation="vertical"
android:id="@+id/vidDurationContainer"
android:visibility="gone" >
<TextView
android:id="@+id/vidDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:paddingLeft="10dip"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Image"
android:textColor="#FFFFFF"
android:textIsSelectable="false"
android:textSize="20sp" />
</LinearLayout>
<CheckBox
android:id="@+id/checkBox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:button="@android:color/transparent"
android:background="@drawable/cameraroll_item_selection" />
</FrameLayout>
我删除了大部分其他代码(由…
)以突出显示我认为最相关的位。问题是这样的:
(1)当我打开图库时:显示“7.0”持续时间的3个缩略图是视频缩略图,第四个是图像
(2)然后我向下滚动多媒体资料,使该行不再可见,然后我向上滚动到此行,这就是我看到的:您可以看到“7.0”不再存在
我怎样才能解决这个问题?预期的行为是,始终为视频缩略图显示持续时间,而不为图像显示持续时间。显然,显示/隐藏持续时间的逻辑有问题。任何帮助都将不胜感激,谢谢
// Gallery.java file
...
public PictureView(...) {
LayoutInflater.from(getContext()).inflate(getResourceId(getContext(), "layout", "view"), this);
vImage = (ImageView)findViewById(getResourceId(getContext(), "id", "vImage"));
checkBox = (CheckBox)findViewById(getResourceId(getContext(), "id", "checkBox"));
vidDurationContainer = (LinearLayout)findViewById(getResourceId(getContext(), "id", "vidDurationContainer"));
vidDuration = (TextView)findViewById(getResourceId(getContext(), "id", "vidDuration"));
}
public void load(...) {
...
vImage.setImageResource(0);
vImage.setVisibility(INVISIBLE);
loader.loadPicture(...);
}
@Override
public void onLoad(PictureInfo picture) {
if (this.pictureInfo != picture) {
return;
}
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
vImage.setImageBitmap(pictureInfo.thumbnail);
vImage.setVisibility(VISIBLE);
if (pictureInfo.isVideo) {
vidDurationContainer.setVisibility(VISIBLE);
vidDuration.setText(String.valueOf(pictureInfo.duration));
} else {
vidDurationContainer.setVisibility(GONE);
}
}
});
}
@Override
public void loadPicture(final PictureInfo pictureInfo, ...) {
...
executor.execute(new Runnable() {
@Override
public void run() {
...
synchronized (pictureCache) {
Bitmap cachedBitmap = pictureCache.get(pictureInfo.uri);
if (cachedBitmap != null) {
pictureInfo.thumbnail = cachedBitmap;
callback.onLoad(pictureInfo);
return;
}
}
...
if (pictureInfo.thumbnail != null) {
callback.onLoad(pictureInfo);
synchronized (pictureCache) {
pictureCache.put(pictureInfo.uri, pictureInfo.thumbnail);
}
}
}
});
}