这件事现在已经开始了一段时间,我似乎无法解决它.
我有一个网格视图,其中显示了一些位图.当我通过适配器填充我的图像视图时,我在所有图像边添加了一个5dp的填充(iv.setPadding(5,5,5,5);),但不知何故,每个顶部和底部都添加了更多的空间我的gridview上的项目.
我知道这已经问一个几 倍这里,有些人甚至已经接受了答案,但是,当我尝试为在URL上的上述起诉的答案,我仍然不断收到对顶部和底部相同的多余的空格.
现在有没有其他方法可以做到这一点?
这是我的一些代码:
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageGrid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:numColumns="6"
/>
Run Code Online (Sandbox Code Playgroud)
grid_item.xml
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid_item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)
我已经尝试将以下内容添加到main.xml中的listselector属性中
以下是顶部和底部多余空间的样子(侧面的那些是我正在添加的如上所述):
关于如何删除那些血腥空间的任何其他想法,以便我的网格视图具有相同的间距?
提前致谢,
我在android中有一个GridView,我用从xml资源中检索的数据填充它.
例如,我在GridView中有15个项目按顺序放置.整体高度超过屏幕高度,所以我必须滚动以查看其余项目.
问题是当我向上滚动时,不可见行的顺序已经改变.这是一种神秘的行为,因为有时项目互相交换行.这是我的getView方法:
public class ImageAdapter extends BaseAdapter {
public ImageAdapter(Context c, NodeList cuu) {
cu = cuu;
}
public int getCount() {
Log.d("Node Count",cu.getLength()+"");
return cu.getLength();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View myView = convertView;
if (convertView == null) {
Node nd = cu.item(position);
Log.d("nodes","Pos: "+(position)+" Name: "+nd.getNodeName()+" Title: "+nd.getAttributes().getNamedItem("title").getTextContent());
int catID = Integer.parseInt(nd.getAttributes().getNamedItem("id").getTextContent());
LayoutInflater li …Run Code Online (Sandbox Code Playgroud) 我遇到了一个非常大的GridView问题.(大约70个孩子)如果我在onCreate上启动它或者在按下主页按钮然后返回后恢复后,GridView工作正常.但是当我从睡眠模式恢复后恢复时,我的BaseAdapter再次启动并破坏了我在运行时对其所做的更改.如果我在重启后调用它,这也会使getChildAt()给出NullPointerException.
我怎样才能让它只是按常规onPause(主页按钮)对GridView进行操作,并避免每次从睡眠模式恢复时GridView被清除?
编辑:我已经尝试为我的Activity类设置一个唤醒锁,它调用BaseAdpter没有运气
2.编辑:自从我发布这个问题以来,我一直试图在onPause中使用此代码恢复GridView:
SparseArray<Parcelable> array = new SparseArray<Parcelable>();
gridView.saveHierarchyState(array);
bundle = new Bundle();
bundle.putSparseParcelableArray("state", array);
Run Code Online (Sandbox Code Playgroud)
这在onResume:
try{
gridView.restoreHierarchyState(bundle.getSparseParcelableArray("state"));
}
catch(Exception e){
//Most likely first start
Log.i("SomeTag", "No GridView state found");
}
}
Run Code Online (Sandbox Code Playgroud)
奇怪的是我在屏幕上似乎从一个地方跳到另一个地方的一切,当我尝试getChildAt()时它仍然崩溃.在睡眠模式之后它也无法获得它.
public View getView(int position,View convertView,ViewGroup parent){
mParentView = parent;
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;
//sets the height for every individual box
int box = width/7*6/10;
ImageCell v = null;
if (convertView == null) {
// If it's …Run Code Online (Sandbox Code Playgroud) 我在本教程中将图像显示在GridView中.我希望能够点击单个图像并执行其他事件,我需要知道点击了什么图像.
我是否必须在ImageAdapter类中添加imageView.onKeyDown(keyCode,event)?这是当前存在的代码:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
// if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
//does this need imageView.onKeyDown(keyCode, event)?
}
else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
Run Code Online (Sandbox Code Playgroud)
它将如何显示点击的图像?如何创建正确的处理程序?
我试图将GridView实现为图库的一部分.我在Android开发人员门户网站上关注了以下示例.
该教程似乎适用于所有屏幕尺寸.如下所示,正确显示小屏幕和大屏幕尺寸的比例(左侧 - 小屏幕尺寸,右侧 - 大屏幕尺寸.

但现在我的问题.当我想在Android项目的LinearLayout中实现完全相同的GridView时 - 正确的比例消失了 - 如下图所示.图片开始重叠等等.

我很确定这与我的LinearLayout有关,如下所示.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget64"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/widget34"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="@drawable/foto_detail_bg_cell_0"
>
<ImageView
android:id="@+id/flyer"
android:layout_width="100dp"
android:layout_height="80dp"
android:src="@drawable/icon"
android:scaleType="centerCrop"
/>
<LinearLayout
android:id="@+id/widget36"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5px"
android:orientation="vertical">
<TextView
android:id="@+id/toptext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beat.It"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@color/white"/>
<TextView
android:id="@+id/widget39"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="http://www.google.at"
android:textColor="@color/white"/>
<LinearLayout
android:id="@+id/widget40"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/widget41"
android:layout_width="58dp"
android:layout_height="40dp"
android:src="@drawable/facebook_share"/>
<ImageView
android:id="@+id/widget42"
android:layout_width="58dp"
android:layout_height="40dp"
android:layout_marginLeft="1dp"
android:src="@drawable/photocount"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" …Run Code Online (Sandbox Code Playgroud) android android-layout screen-size android-linearlayout android-gridview
我有一个活动,它从列表中输出json数据.但现在我想在一个片段中实现它.在这个片段中,我想将其视为gridview.这两个文件都运行正常.但是当我尝试实现AsyncTask时,我得到几个redflags作为无法访问的代码.请有人帮我这个吗?
编辑:新的
public class SalesFragment extends Fragment {
GridView gridView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View gv = inflater.inflate(R.layout.hot_sales, null);
gridView = (GridView) gv.findViewById(R.id.grid_view);
bindGridview();
return gv;
}
public void bindGridview() {
new MyAsyncTask(getActivity(),gridView).execute("");
}
class MyAsyncTask extends AsyncTask<String, String, String> {
GridView mGridView;
Activity mContext;
Response response;
public MyAsyncTask(Activity context,GridView gview) {
this.mGridView=gview;
this.mContext=context;
}
protected String doInBackground(String... params) {
File file = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/sample.txt");
if(file.exists()) {
try{
Reader inputStreamReader …Run Code Online (Sandbox Code Playgroud) android gson android-gridview android-asynctask android-fragments
我有一个gridview,其中每个项目都有两个元素,第一个是图像,第二个是标题,标题在启动应用程序时是不可见的,但我在网格视图外面有一个按钮,我点击它,我想改变项目标题的可见性变得可见,我的问题是我无法访问网格视图中每个项目的每个标题.当我在活动中的独立按钮的onClick方法中设置标题(TextView)的可见性时,它仅更改网格视图中FIRST项目的可见性!
这个草图代表我的界面,因此标题在开头是不可见的,但是当我点击"SetVisibilityButton"时,我想将它们设置为Visible:
Image1 Image2 Image3
Title1 Title2 Title3
Image4 Image5 Image6
Title4 Title5 Title6
Image7 Image8 Image9
Title7 Title8 Title9
----------------------------
SetVisibilityButton
____________________________
Run Code Online (Sandbox Code Playgroud)
我在oncreate()活动中设置了网格视图:
favorGrid = (GridView) findViewById(R.id.favorGrid);
favorGrid.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
在我的ImageAdapter类中,这是我的getView()方法:
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View MyView = convertView;
/*we define the view that will display on the grid*/
//Inflate the layout
LayoutInflater li = getLayoutInflater();
MyView = li.inflate(R.layout.favor_item, null);
// Add The Text!!!
TextView tv = (TextView)MyView.findViewById(R.id.title);
tv.setText(mTitles[position]);
// Add The Image!!!
ImageView iv …Run Code Online (Sandbox Code Playgroud) 我已经忍受了几个月和几个月的问题(但现在我正在进行性能调整).但是,我现在迫切需要知道为什么我的适配器感觉有必要bindView在记录上运行多达4次.
我有一个自定义游标适配器填充gridview.
一些调试显示正在发生的事情:
03-08 14:46:47.980: I/AdapterCursorGrid(20724): newView()
03-08 14:46:48.470: I/AdapterCursorGrid(20724): bindView()
03-08 14:46:48.570: I/AdapterCursorGrid(20724): --------------------------
03-08 14:46:48.570: I/AdapterCursorGrid(20724): bindView() Record Id: 1
03-08 14:46:48.570: I/AdapterCursorGrid(20724): bindView() Cursor Position: 0
03-08 14:46:48.570: I/AdapterCursorGrid(20724): bindView() View Type: 0
03-08 14:46:48.570: I/AdapterCursorGrid(20724): --------------------------
03-08 14:46:48.600: D/AdapterCursorGrid(20724): bindView() Avatar empty...
03-08 14:46:48.690: D/AdapterCursorGrid(20724): bindView() Picture creation...
03-08 14:46:49.490: I/AdapterCursorGrid(20724): bindView()
03-08 14:46:49.501: I/AdapterCursorGrid(20724): --------------------------
03-08 14:46:49.501: I/AdapterCursorGrid(20724): bindView() Record Id: 1
03-08 14:46:49.501: I/AdapterCursorGrid(20724): bindView() Cursor Position: 0
03-08 14:46:49.501: I/AdapterCursorGrid(20724): bindView() …Run Code Online (Sandbox Code Playgroud) 我有一个网格视图,我使用自定义适配器填充.在填充gridview时,我将每个元素放在一个唯一标记内.
填充此gridview之后,我希望在gridview中找到其标记的特定元素.我怎么找到这个?
目前我这样做:
gridviewobject.findViewById(thetag);
// gridview object is the object of the gridview that i have populated.
Run Code Online (Sandbox Code Playgroud) 我正在使用Universal Image Loader 1.8.6库来加载从网络上拍摄的动态图像.
的ImageLoaderConfiguration配置如下:
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.memoryCacheExtraOptions(480, 800) // default = device screen dimensions
.threadPoolSize(3) // default
.threadPriority(Thread.NORM_PRIORITY - 1) // default
.denyCacheImageMultipleSizesInMemory()
.memoryCacheSize(2 * 1024 * 1024)
.memoryCacheSizePercentage(13) // default
.discCacheSize(50 * 1024 * 1024)
.discCacheFileCount(100)
.imageDownloader(new BaseImageDownloader(getApplicationContext())) // default
.defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
.writeDebugLogs()
.build();
Run Code Online (Sandbox Code Playgroud)
并且DisplayImageOptions配置是:
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.no_foto)
.showImageForEmptyUri(R.drawable.no_foto)
.showImageOnFail(R.drawable.no_foto)
.build();
Run Code Online (Sandbox Code Playgroud)
我的ArrayAdapter中的getView方法包含以下代码:
iv.setImageResource(R.drawable.no_foto);
imageLoader.displayImage(basePath+immagine, iv);
Run Code Online (Sandbox Code Playgroud)
上面代码的第一行用于避免gridView中的视图回收允许将图像设置在错误的位置(直到图片没有下载).
实际问题是这样的:
如果我打开我的Activity(包含GridView)所显示的项目,感谢UIL库可以下载图像.(同时no_foto.png图像显示在网格的每个视图中).当所有视图都加载了自己的图像时,如果我尝试向下滚动然后我回来(向上滚动)我必须等待图像重新加载,因为所有视图现在都被no_foto.png图像占用.
如何避免重载这些图像?使用Universal …
android android-imageview android-gridview android-view universal-image-loader
android ×10
android-gridview ×10
android-view ×1
baseadapter ×1
gridview ×1
gson ×1
java ×1
lifecycle ×1
screen-size ×1