Questions tagged «android»

Android是Google的移动操作系统,用于对数字设备(智能手机,平板电脑,汽车,电视,Wear,Glass和IoT)进行编程或开发。对于与Android相关的主题,请使用特定于Android的标签,例如android-intent,android-activity,android-adapter等。对于与开发或编程无关但与Android框架相关的问题,请使用以下链接:https:// android.stackexchange.com。

14
如何用布局使一个视图膨胀
我有一个用XML定义的布局。它还包含: <RelativeLayout android:id="@+id/item" android:layout_width="fill_parent" android:layout_height="wrap_content" /> 我想将此RelativeView与其他XML布局文件一起充气。我可能会根据情况使用不同的布局。我该怎么办?我正在尝试不同的 RelativeLayout item = (RelativeLayout) findViewById(R.id.item); item.inflate(...) 但是他们都不行。

15
通过意图传递枚举或对象(最佳解决方案)
我有一个活动,启动时需要访问两个不同的ArrayList。这两个列表都是我创建的不同对象。 基本上,我需要一种将这些对象从Intent传递到活动的方法。我可以使用addExtras(),但这需要一个Parceable兼容类。我可以使我的类通过序列化传递,但是据我了解,这会使程序变慢。 我有什么选择? 我可以通过枚举吗? 顺便说一句:有没有办法将参数从Intent传递给Activity构造函数?
221 android 


10
将Float格式化为n个小数位
我需要将浮点数格式化为“ n”个小数位。 试图使用BigDecimal,但返回值不正确... public static float Redondear(float pNumero, int pCantidadDecimales) { // the function is call with the values Redondear(625.3f, 2) BigDecimal value = new BigDecimal(pNumero); value = value.setScale(pCantidadDecimales, RoundingMode.HALF_EVEN); // here the value is correct (625.30) return value.floatValue(); // but here the values is 625.3 } 我需要返回一个浮点数,该浮点数具有指定的小数位数。 我不需要Float价值回报Double 。


6
加载内容时在ImageView中使用“动画圆”
我当前在我的应用程序中使用的列表视图可能需要一秒钟才能显示出来。 我目前正在使用列表视图的@ id / android:empty属性创建“正在加载”文本。 <TextView android:id="@id/android:empty" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FF0000" android:text="Loading..."/> 现在,我想用在加载对话框中使用的动画圆代替此文本替换它,我想你们都知道我的意思: 编辑:我不想对话框。我想在我的布局中显示出来。 非常感谢您的帮助!


21
在Android上调整大位图文件的大小以缩放输出文件
我在文件中有一个大的位图(例如3888x2592)。现在,我想将该位图的大小调整为800x533并将其保存到另一个文件中。我通常会通过调用Bitmap.createBitmapmethod 来缩放位图,但是它需要源位图作为第一个参数,我无法提供,因为将原始图像加载到Bitmap对象中当然会超出内存(例如,请参见此处)。 我也无法读取与位图,例如BitmapFactory.decodeFile(file, options),提供了BitmapFactory.Options.inSampleSize,因为我想将它调整到一个确切的宽度和高度。使用inSampleSize会将位图的大小调整为972x648(如果使用inSampleSize=4)或778x518(如果使用inSampleSize=5,则甚至不是2的幂)。 我还想避免在第一步中使用inSampleSize读取图像,例如,在972x648上读取图像,然后在第二步中将其尺寸调整为恰好为800x533,因为与直接调整原始图像的尺寸相比,其质量很差。 总结一下我的问题:是否可以读取10MP或更大的大图像文件并将其保存到新的图像文件中,并调整大小为特定的新宽度和高度,而不会出现OutOfMemory异常? 我还尝试BitmapFactory.decodeFile(file, options)将Options.outHeight和Options.outWidth值手动设置为800和533,但这种方式不起作用。
218 android  image  resize  bitmap 

3
如何将baselineAligned设置为false,如何提高LinearLayout的性能?
我只是在xml中构建一些UI,Lint给了我一个警告,并说将android:baselineAligned设置为false以提高ListView的性能。 Lint更改的文档添加了此警告,说 布局性能:查找具有权重的LinearLayouts,应在其中设置android:baselineAligned =“ false”以获得更好的性能,并查找嵌套权重会导致性能问题的情况。 有人可以解释为什么这样做可以改善性能,特别是在涉及体重时?

7
如何在Android中从Java端将android:gravity设置为TextView
我可以android:gravity="bottom|center_horizontal"在textview的xml 中使用以获得所需的结果,但是我需要以编程方式进行此操作。我的textview在a内tablerow是否重要relativelayout。 我努力了: LayoutParams layoutParams = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL); labelTV.setLayoutParams(layoutParams); 但是,如果我理解正确,那可以将其应用于tablerow,而不是textview吗?

11
以编程方式返回到后堆栈中的上一个片段
假设我有一个活动,其中包含以编程方式添加的片段: private void animateToFragment(Fragment newFragment, String tag) { FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.fragment_container, newFragment, tag); ft.addToBackStack(null); ft.commit(); } 返回到可见的先前片段的最佳方法是什么? 我发现在Android中单击按钮时具有触发器后退按钮功能,但我认为模拟后退键事件不是正确的解决方法(而且我也无法使其正常工作): dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)); 调用finish()只会关闭我不感兴趣的活动。 有更好的方法来解决这个问题吗?


30
检查EditText是否为空。[关闭]
已关闭。这个问题需要更加集中。它当前不接受答案。 想改善这个问题吗?更新问题,使其仅通过编辑此帖子来关注一个问题。 2年前关闭。 改善这个问题 我EditTexts在Android中有5个供用户输入。我想知道是否有一种方法可以检查所有5个EditTexts是否为空。有什么办法吗?

21
GridLayout(不是GridView)如何均匀拉伸所有子级
我想要一个2x2的网格,里面有一个按钮。这只是ICS,所以我尝试使用给定的新GridLayout。 这是我的布局的XML: <?xml version="1.0" encoding="utf-8"?> <GridLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/favorites_grid" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#00ff00" android:rowCount="2" android:columnCount="2"> <Button android:text="Cell 0" android:layout_row="0" android:layout_column="0" android:textSize="14dip" /> <Button android:text="Cell 1" android:layout_row="0" android:layout_column="1" android:textSize="14dip" /> <Button android:text="Cell 2" android:layout_row="1" android:layout_column="0" android:textSize="14dip" /> <Button android:text="Cell 3" android:layout_row="1" android:layout_column="1" android:textSize="14dip" /> </GridLayout> 问题是我的视图对每一行的伸展不均匀。这在我的GridLayout的右边导致了很多额外的空间。 我尝试设置,layout_gravity="fill_horizontal"但这仅适用于该行的最后一个视图。这意味着单元1一直伸展到为单元0提供足够的空间。 关于如何解决这个问题的想法?


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.