我从db填充了gridview。当我打开一些图像时,它们会卡在布局的顶部。可能导致什么?
我注意到一些图像直接在布局中间打开,这是我真正想要的。而一些图像只是"下降"双击后缩小它们,在正确的位置。
Gridview活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_grid_view);
TextView id = (TextView) findViewById(R.id.i_id);
Intent i = getIntent();
i_id = i.getStringExtra(TAG_ID);
id.setText(i_id);
mGridView = (GridView) findViewById(R.id.gridView);
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
//Initialize with empty data
mGridData = new ArrayList<>();
mGridAdapter = new GridViewAdapter(this, R.layout.grid_item_layout, mGridData);
mGridView.setAdapter(mGridAdapter);
//Grid view click event
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//Get item at position
GridItem item = (GridItem) parent.getItemAtPosition(position);
Intent intent = new Intent(GridViewActivity.this, DetailsActivity.class);
intent.putExtra("image", item.getImage());
startActivity(intent);
}
});
//Start download
new AsyncHttpTask().execute(FEED_URL);
mProgressBar.setVisibility(View.VISIBLE);
}
详情活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
Intent i = getIntent();
String image = i.getStringExtra("image");
//Set image url
imageView = (ImageView) findViewById(R.id.grid_item_image);
Picasso.with(DetailsActivity.this).load(image).into(imageView);
mAttacher = new PhotoViewAttacher(imageView);
Uri bmpUri = getLocalBitmapUri(imageView);
shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
}
Gridview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f0f0f0">
<TextView
android:id="@+id/i_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IDDD"
android:visibility="gone"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ilustrativas"
android:id="@+id/ilustrativas"
android:layout_above="@+id/likes_count"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="10dp"
android:textSize="12sp"
android:textStyle="italic" />
<GridView
android:id="@+id/gridView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_below="@+id/ilustrativas"
android:columnWidth="100dp"
android:drawSelectorOnTop="true"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp"
android:focusable="true"
android:clickable="true"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_centerInParent="true"
android:visibility="gone"/>
</RelativeLayout>
Details.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_background"
android:background="#000">
<ImageView
android:id="@+id/grid_item_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:scaleType="fitCenter" />
</RelativeLayout>
GridItem.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#f1f1f1"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:id="@+id/grid_item_image"
android:layout_width="100dp"
android:scaleType="fitCenter"
android:layout_height="100dp" />
</LinearLayout>
答案 0 :(得分:0)
我自己发现了这个错误。我不知道为什么但PhotoviewAttacher造成了这个问题。刚删除它并使用此课程https://github.com/MikeOrtiz/TouchImageView