我有一个gridview用按钮显示图像,但我有一个问题,它只显示第一行,我发送3行数据..
这是我的布局代码:
<?xml version="1.0" encoding="utf-8"?><!-- To make screen scroll in vertical direction -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapthumbnail="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="@drawable/fondodroid2"
android:orientation="vertical">
<!-- Main layout -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fefdff"
android:layout_marginLeft="@dimen/login_activity_horizontal_margin"
android:layout_marginRight="@dimen/login_activity_horizontal_margin"
android:layout_marginTop="@dimen/login_activity_vertical_margin"
android:padding="@dimen/login_activity_horizontal_margin"
android:id="@+id/linearLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_marginBottom="@dimen/login_activity_vertical_margin"
android:weightSum="1">
<ImageView
android:layout_width="@dimen/login_activity_logo"
android:layout_height="@dimen/login_activity_logo"
android:id="@+id/imageView"
android:src="@drawable/logo"
android:contentDescription="Icon GG"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/files"
android:id="@+id/textView"
android:textSize="@dimen/login_activity_text"
android:textColor="@android:color/black"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView"
android:layout_marginLeft="10dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="@+id/relativeLayout">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:background="#686868"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:text="@string/sign_string"
android:textSize="@dimen/login_activity_vertical_margin"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/linearSign"
android:layout_centerInParent="true"
android:background="#cccccc"
android:visibility="gone">
<ImageView
android:id="@+id/sign_thumb"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_margin="3dp"></ImageView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="@+id/sign_thumb"
android:layout_alignEnd="@+id/sign_thumb">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eliminar"
android:id="@+id/deleteButton"
android:background="#cc6b67"
android:textStyle="bold"
android:layout_marginBottom="8dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="@+id/relativeLayout2"
android:layout_marginTop="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:background="#686868"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:text="@string/images"
android:textSize="@dimen/login_activity_vertical_margin"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/linearLayout2">
<GridView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/gridImages"
android:numColumns="2"
android:layerType="hardware"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="@dimen/login_activity_logo_h"
android:layout_height="@dimen/login_activity_logo_v"
android:id="@+id/imageView2"
android:src="@drawable/logo"
android:layout_below="@+id/linearLayout"
android:layout_alignRight="@+id/linearLayout"
android:layout_marginTop="@dimen/login_activity_vertical_margin"
android:layout_marginBottom="@dimen/login_activity_vertical_margin"
android:contentDescription="@string/logo" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
在适配器中我没有任何扼杀,但如果你需要我在这里复制..我尝试使用fill_parent wrap_content等但没有任何作用..
编辑:适配器代码:
public class GridAdapter extends BaseAdapter {
private LayoutInflater inflater;
private Activity activity;
private List<String> images = new ArrayList<String>();
private OnDeleteItem mListener;
public interface OnDeleteItem {
public void onDeleteItemClick(String path);
}
public GridAdapter(Activity inyectActivity, List<String> listImages) {
activity = inyectActivity;
images = listImages;
inflater = LayoutInflater.from(activity);
mListener = (ReviewFilesActivity) activity;
}
public void notifyDataSetChanged(List<String> dataImages) {
images = dataImages;
super.notifyDataSetChanged();
}
public View getView(final int position, View convertView, ViewGroup parent) {
GridViewHolder vHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.grid_view, null);
vHolder = new GridViewHolder(convertView, mListener);
vHolder.image.setImageBitmap(ImagesUtilities.decodeSampledBitmapFromResource(images.get(position), 400, 400));
vHolder.path = images.get(position);
vHolder.delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.onDeleteItemClick(images.get(position));
}
});
} else {
vHolder = (GridViewHolder) convertView.getTag();
}
return convertView;
}
@Override
public int getCount() {
return images.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
static class GridViewHolder {
public GridViewHolder(View view, OnDeleteItem listener) {
ButterKnife.inject(this, view);
}
@InjectView(R.id.grid_item_image)
ImageView image;
@InjectView(R.id.deleteButton)
Button delete;
String path;
public String getPath() {
return path;
}
}
}
EDIT2:
我更简单地使用XML,但行不显示。
<?xml version="1.0" encoding="utf-8"?><!-- To make screen scroll in vertical direction -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="@drawable/fondodroid2"
android:orientation="vertical">
<!-- Main layout -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fefdff"
android:layout_marginLeft="@dimen/login_activity_horizontal_margin"
android:layout_marginRight="@dimen/login_activity_horizontal_margin"
android:layout_marginTop="@dimen/login_activity_vertical_margin"
android:padding="@dimen/login_activity_horizontal_margin"
android:id="@+id/linearLayout">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_marginBottom="@dimen/login_activity_vertical_margin"
android:weightSum="1">
<ImageView
android:layout_width="@dimen/login_activity_logo"
android:layout_height="@dimen/login_activity_logo"
android:id="@+id/imageView"
android:src="@drawable/logo"
android:contentDescription="Icon GG"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/files"
android:id="@+id/textView"
android:textSize="@dimen/login_activity_text"
android:textColor="@android:color/black"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView"
android:layout_marginLeft="10dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/relativeLayout"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:text="@string/sign_string"
android:textSize="@dimen/login_activity_vertical_margin"
android:textStyle="bold"
android:background="#686868"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:gravity="center"
android:id="@+id/textView3" />
<ImageView
android:id="@+id/sign_thumb"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_alignParentEnd="false"
android:visibility="gone" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eliminar"
android:id="@+id/deleteButton"
android:background="#cc6b67"
android:textStyle="bold"
android:layout_alignBottom="@+id/textView3"
android:layout_alignParentStart="true"
android:visibility="gone" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="@+id/relativeLayout2"
android:layout_marginTop="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="@android:color/white"
android:text="@string/images"
android:textSize="@dimen/login_activity_vertical_margin"
android:textStyle="bold"
android:background="#686868"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:gravity="center"
android:id="@+id/textView2" />
<GridView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/gridImages"
android:numColumns="2"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp"
android:layout_alignParentLeft="false"
android:layout_marginLeft="0dp"
android:layout_below="@+id/textView2" />
</RelativeLayout>
</LinearLayout>
<ImageView
android:layout_width="@dimen/login_activity_logo_h"
android:layout_height="@dimen/login_activity_logo_v"
android:id="@+id/imageView2"
android:src="@drawable/logo"
android:layout_below="@+id/linearLayout"
android:layout_alignRight="@+id/linearLayout"
android:layout_marginTop="@dimen/login_activity_vertical_margin"
android:layout_marginBottom="@dimen/login_activity_vertical_margin"
android:contentDescription="@string/logo" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
答案 0 :(得分:0)
以下是实现所需布局的一些简化示例
<?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"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_icon" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/sign_thumb"
android:layout_width="match_parent"
android:layout_height="100dp"
android:src="@drawable/ic_icon" />
<Button
android:id="@+id/deleteButton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<GridView
android:id="@+id/gridImages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="2" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_icon" />
</LinearLayout>