该GridLayoutAPI文档是非常难学......
有谁可以教我如何设置儿童的任何一个Views到有类似的"权重" LinearLayout?
现在看起来所有的都放在左侧,
我已经尝试了很多次,但仍然不能像屏幕的半宽一样.
编辑:我不知道什么时候我可以为孩子做什么wrap_content......即使我想设置一些特定大小的图像,这个班有助于我做ImageView wrap_content.........它不能正常运行,我错过了一些设置吗?!?
在较新的Android版本上,以下代码:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#bdbdbd" />
<size
android:width="60dp"
android:height="60dp" />
</shape>
</item>
<item
android:drawable="@drawable/ic_library_books_black_24dp"
android:gravity="center"
android:width="40dp"
android:height="40dp"
>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
完美地生产:
然而,早期的Android版本(API 16和19,来自我测试过的)根本不喜欢这个,我得到了
E/AndroidRuntime: FATAL EXCEPTION: main
Process: package.app, PID: 11490
android.view.InflateException: Binary XML file line #26: Error inflating class ImageView
Run Code Online (Sandbox Code Playgroud)
通货膨胀.我用过app:srcCompat所有的ImageViews,所以没有问题.
标准矢量Drawables也可以正常工作,但放在layer-list它们时会造成混乱.有没有解决方法?
我要发布我的应用程序,它是一个1.2Mb的apk,包括4种不同格式的大约120个图标(ldpi,mdpi,hdpi,x-hdpi).
如果我添加xx-dpi和xxx-hdpi图标,apk会变大,加载时间会增加.
有许多入门级设备,内存非常loooow,我希望我的应用程序可以在任何地方运行.
我真的需要添加xx-hdpi吗?
是否有真正的设备需要xxx-hdpi?
是有什么区别getHeight()和getLayoutParams().height的View?我有一个View(GoogleAdView),我想隐藏它,我设置getLayoutParams().height为零,但广告的高度(ad.getHeight())不是零.
有没有办法隐藏View它,以便它不占用布局中的空间?
我试图将其可见性设置为GONE或设置ad.getLayoutParams().height为零,但这不起作用.
在我的应用程序中,除了一个特定的模式外,我在纵向模式下FragmentActivity有多个.我之间移动通过尾小号S IN的.FragmentFragmentFragmentViewFragmentActivity
当有方向改变时,我有一个不同的布局(实际上具有相同的名称但不同的小部件View)Fragment.在横向模式下,我想从Fragment布局View和页脚View中删除特定的小部件FragmentActivity,当回到纵向时,将所有内容添加回来.
我已经保存了所需的所有数据,但我最好onSavedInstanceState()在Fragment哪里测试方向更改,以便我可以View适当地恢复?
不知道我可以覆盖onConfigurationChange(),并在我的测试有Fragment,因为我不具备的机器人:configChanges ="方向"在我的Android Manifest.
在android Java上工作,最近将SDK更新到API级别29,现在显示警告,指出
Environment.getExternalStorageDirectory() 在API级别29中已弃用
我的代码是
private void saveImage() {
if (requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
final String folderPath = Environment.getExternalStorageDirectory() + "/PhotoEditors";
File folder = new File(folderPath);
if (!folder.exists()) {
File wallpaperDirectory = new File(folderPath);
wallpaperDirectory.mkdirs();
}
showLoading("Saving...");
final String filepath=folderPath
+ File.separator + ""
+ System.currentTimeMillis() + ".png";
File file = new File(filepath);
try {
file.createNewFile();
SaveSettings saveSettings = new SaveSettings.Builder()
.setClearViewsEnabled(true)
.setTransparencyEnabled(true)
.build();
if(isStoragePermissionGranted() ) {
mPhotoEditor.saveAsFile(file.getAbsolutePath(), saveSettings, new PhotoEditor.OnSaveListener() {
@Override
public void onSuccess(@NonNull String imagePath) {
hideLoading();
showSnackbar("Image Saved …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序小部件,可以onUpdate()在我的提供程序中接收click事件.
但是,当我尝试强制关闭主启动器时,单击事件将丢失.
我甚至把断点在所有的onEnabled(),onReceived()...等:连接似乎丢失.
因此,我如何"重新连接"按钮事件?
WidgetProvider扩展AppWidgetProvider:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Log.d(TAG, "onUpdate()");
Log.d(TAG, "isLoading: " + CONSTANT.isLoading);
// update each of the widgets with the remote adapter from updateService
// Get all ids
ComponentName thisWidget = new ComponentName(context, ScoreWidgetProvider.class);
int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
// Build the intent to call the service
Intent intent = new Intent(context.getApplicationContext(), UpdateWidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds);
// Update the widgets via the service
context.startService(intent); …Run Code Online (Sandbox Code Playgroud) 昨天,我已切换到Android Studio 2.1.3版.今天,我重新打开了我的一个项目,并试图添加一些图层列表drawables用于ImageView.例如这一个:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:width="80px" android:height="80px"
android:top="0px" android:left="0px"
android:right="0px" android:bottom="0px">
<shape android:shape="rectangle">
<solid android:color="@color/deep_orange"/>
</shape>
</item>
<item android:width="60px" android:height="60px"
android:top="10px" android:left="10px"
android:right="10px" android:bottom="10px">
<shape android:shape="oval">
<solid android:color="@color/light_yellow"/>
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
这是我在升级Android Studio版本之前所获得的,如果我选择23作为"在IDE中渲染布局时使用的Android版本",这就是我现在在预览中获得的内容.
但是,如果我选择23以下的任何版本,我只会得到正方形:
不幸的是,在模拟器(Lollipop 22)或设备(Jellybean 18)上运行应用程序时,我也得到了正方形.
以防这有用:
Activity延伸AppCompatActivity我认为这个问题在某种程度上关系到使用的top,left,right并bottom为上层.因为如果我只是在一个正方形的顶部放置一个圆圈,预览以及"真实的东西"将按预期的方式对所有API级别起作用.
编辑我也开始了一个全新的项目,使用相同的代码/ xml和以下(自动创建)build.gradle:
Activity延伸 …我想表明我的每个单元格内剩下多少时间RecyclerView......因为我已经为每个单元格使用了倒数计时器.在每一行我开始一个计数器并管理onTick()...所有工作都按预期工作...我有一个计时器勾选每一行,我的单元格也在更新但我的单元格现在闪烁....当它变得疯狂时我滚动.
这是我的适配器......
if (product.getProductType().equalsIgnoreCase("Auction Product")) {
isAuction=true;
viewHolder.img_product_type.setImageResource(R.drawable.bid);
viewHolder.txt_timeleft.setVisibility(View.VISIBLE);
start_countDown(product.getStart(),product.getStop(),viewHolder.txt_timeleft);
}
Run Code Online (Sandbox Code Playgroud)
计数器代码如下....
private void start_countDown(String start, String stop, final TextView txt_timeleft) {
try {
//Log.e("hetal",start+"....."+stop);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar start_date = Calendar.getInstance();
start_date.setTime(format.parse(start));
Calendar end_date = Calendar.getInstance();
end_date.setTime(format.parse(stop));
final Calendar today = Calendar.getInstance();
CountDownTimer timer;
txt_timeleft.setTextColor(Color.DKGRAY);
if(today.before(start_date)){
txt_timeleft.setTextColor(context.getResources().getColor(R.color.red));
txt_timeleft.setText(context.getString(R.string.auction_not_start));
Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(1000); //You can manage the time of the blink with this parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
txt_timeleft.startAnimation(anim);
return;
} …Run Code Online (Sandbox Code Playgroud)