Android上的网格视图布局有问题.我找不到解决方案来消除网格视图中的额外空间.我尝试了很多东西(numColumns,columnWidth,stretchMode,gravity)和建议(来自StackOverflow),但没有任何工作正常.我花了将近8个小时来解决这个问题.这是一个网格视图代码:
<GridView
android:id="@+id/lookbook_gridview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="@null"
android:padding="0dip"
android:layout_margin="0dip"
android:verticalSpacing="0px"
android:horizontalSpacing="0px"
android:numColumns="auto_fit"
android:columnWidth="160px"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_gravity="center"
android:background="#000"
android:cacheColorHint="#000"
android:descendantFocusability="afterDescendants"
android:layout_alignParentTop="true"
android:layout_above="@id/buttons">
</GridView>
Run Code Online (Sandbox Code Playgroud)
我还试图以编程方式减少额外空间:
private void setGridview()
{
GridView gridview = (GridView) findViewById(R.id.lookbook_gridview);
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int gridSize = display.getWidth();
int count = gridSize / 160; // image has 160x160 px
int colWidth = (gridSize / count) - PADDING;
gridview.setColumnWidth(colWidth);
gridview.setNumColumns(count);
}
Run Code Online (Sandbox Code Playgroud)
但它仅适用于我的HTC Desire(右),但在模拟器(左)具有相同的显示分辨率和相同的API版本 - 它不起作用.
有人知道,如何在gridview中设置图像而没有任何特殊的填充或空间来成功地与所有分辨率和设备一起工作?
我正在创建一个简单的图像编辑器应用程序,因此需要加载和保存图像文件。我希望保存的文件在单独的相册中显示在图库中。从Android API 28到29,应用程序可以访问存储的程度发生了巨大变化。我可以在Android Q(API 29)中做我想做的事,但是这种方式并不向后兼容。
当我想在较低的API版本中获得相同的结果时,到目前为止,我只能找到方法,这需要使用不赞成使用的代码(从API 29开始)。
这些包括:
MediaStore.Images.Media.DATA
列的使用Environment.getExternalStoragePublicDirectory(...)
MediaStore.Images.Media.insertImage(...)
我的问题是:是否有可能以这种方式实现它,使其向后兼容,但不需要弃用的代码?如果不是,在这种情况下可以使用不赞成使用的代码,还是可以将这些方法很快从sdk中删除?无论如何,使用不推荐使用的方法感觉很不好,所以我宁愿不:)
这是我发现可与API 29一起使用的方法:
ContentValues values = new ContentValues();
String filename = System.currentTimeMillis() + ".jpg";
values.put(MediaStore.Images.Media.TITLE, filename);
values.put(MediaStore.Images.Media.DISPLAY_NAME, filename);
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
values.put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis() / 1000);
values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
values.put(MediaStore.Images.Media.RELATIVE_PATH, "PATH/TO/ALBUM");
getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);
Run Code Online (Sandbox Code Playgroud)
然后,我使用insert方法返回的URI保存位图。问题在于,在API 29中引入了RELATIVE_PATH字段,因此当我在较低版本上运行代码时,图像将放入“ Pictures”文件夹,而不是“ PATH / TO / ALBUM”文件夹。
image backwards-compatibility mediastore subdirectory android-10.0
我在Eclipse Indigo中安装PyDev时遇到问题.我使用了帮助 - >安装新软件 - >和http://pydev.org/updates存储库.我尝试了3天但它仍然无法正常工作.首先,我收到错误:无法读取存储库.
今天,找到了存储库,但在安装包时出现错误:
收集要安装的项目会话上下文时发生错误:(profile = epp.package.java,phase = org.eclipse.equinox.internal.p2.engine.phases.Collect,operand =,action =).无法在http://update-production-pydev.s3.amazonaws.com/pydev/updates/plugins/org.python.pydev_2.2.2.2011082312.jar上阅读存储库.读取超时无法在http://update-production-pydev.s3.amazonaws.com/pydev/updates/plugins/org.python.pydev.debug_2.2.2.2011082312.jar中读取存储库.读取超时无法在http://update-production-pydev.s3.amazonaws.com/pydev/updates/plugins/org.python.pydev.jython_2.2.2.2011082312.jar上读取存储库.读取超时
好像存储库出了故障.有人知道,该怎么办?谢谢!
在我的Android应用程序中,我有一组带有一组按钮的GridView布局.问题是,我无法正确设置按钮上的焦点(我的意思是光标,在Android设备上用操纵杆控制).我可以用图片描述我的问题:
我使用LayoutInflater在BaseAdapter的代码中动态地将Buttons设置为GridView.在代码中,我设置了按钮的文本,图像(CompoundDrawable)和背景颜色,因为我的按钮就像一个复选框(蓝色背景意味着已选中).
看起来该程序正在关注网格字段而不是按钮本身.我的意思是像桌子的单元格,而不是表格中的按钮.因为焦点颜色是默认值(绿色),但我在选择器中设置了蓝色.焦点按也不起作用.而按钮的界限明显偏离按钮.有人可以帮我解决这个问题吗?我的XML布局代码:
main.xml中:
...
<GridView
android:id="@+id/channels"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="6dip"
android:verticalSpacing="10dip"
android:horizontalSpacing="10dip"
android:numColumns="auto_fit"
android:columnWidth="60dip"
android:stretchMode="columnWidth"
android:gravity="center"
android:background="@color/container_main">
</GridView>
...
Run Code Online (Sandbox Code Playgroud)
channel.xml:
<Button
android:id="@+id/channel"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:gravity="center_horizontal"
android:background="@color/willBeSetInAdapter" <!-- white/blue/darkblue focus background -->
android:drawableTop="@drawable/willBeSetInAdapter" <!-- icon -->
android:drawablePadding="0dip"
android:text="WillBeSetInAdapter" <!-- label text -->
android:textColor="@color/text_container_main"
android:textSize="12sp"
android:focusable="true"
android:focusableInTouchMode="false">
</Button>
Run Code Online (Sandbox Code Playgroud)
我试图在Button和GridView中设置焦点参数,并尝试了很多东西,但不幸的是它仍然无法正常工作:(
android ×2
gridview ×2
android-10.0 ×1
button ×1
eclipse ×1
focus ×1
image ×1
installation ×1
layout ×1
mediastore ×1
padding ×1
pydev ×1
python ×1
stretch ×1
subdirectory ×1