小编0X0*_*gar的帖子

如何使GridLayout适合屏幕大小

GridLayoutAPI文档是非常难学......
有谁可以教我如何设置儿童的任何一个Views到有类似的"权重" LinearLayout

现在看起来所有的都放在左侧,
我已经尝试了很多次,但仍然不能像屏幕的半宽一样.

编辑:我不知道什么时候我可以为孩子做什么wrap_content......即使我想设置一些特定大小的图像,这个班有助于我做ImageView wrap_content.........它不能正常运行,我错过了一些设置吗?!?

android widget

34
推荐指数
3
解决办法
11万
查看次数

在较旧的Android版本的图层列表中的矢量Drawable

在较新的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)

完美地生产:

导航drawable显示在灰色圆背景的白色名单

然而,早期的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它们时会造成混乱.有没有解决方法?

android drawable android-vectordrawable

31
推荐指数
3
解决办法
1万
查看次数

Android xxx-hdpi真实设备

我要发布我的应用程序,它是一个1.2Mb的apk,包括4种不同格式的大约120个图标(ldpi,mdpi,hdpi,x-hdpi).

如果我添加xx-dpi和xxx-hdpi图标,apk会变大,加载时间会增加.
有许多入门级设备,内存非常loooow,我希望我的应用程序可以在任何地方运行.

我真的需要添加xx-hdpi吗?

是否有真正的设备需要xxx-hdpi?

icons android dpi android-icons

24
推荐指数
5
解决办法
7万
查看次数

getHeight()vs getLayoutParams().height

是有什么区别getHeight()getLayoutParams().heightView?我有一个View(GoogleAdView),我想隐藏它,我设置getLayoutParams().height为零,但广告的高度(ad.getHeight())不是零.

有没有办法隐藏View它,以便它不占用布局中的空间?

我试图将其可见性设置为GONE或设置ad.getLayoutParams().height为零,但这不起作用.

height android view

15
推荐指数
2
解决办法
2万
查看次数

在哪里检查android片段中的方向更改

在我的应用程序中,除了一个特定的模式外,我在纵向模式下FragmentActivity有多个.我之间移动通过尾小号S IN的.FragmentFragmentFragmentViewFragmentActivity

当有方向改变时,我有一个不同的布局(实际上具有相同的名称但不同的小部件View)Fragment.在横向模式下,我想从Fragment布局View和页脚View中删除特定的小部件FragmentActivity,当回到纵向时,将所有内容添加回来.

我已经保存了所需的所有数据,但我最好onSavedInstanceState()Fragment哪里测试方向更改,以便我可以View适当地恢复?

不知道我可以覆盖onConfigurationChange(),并在我的测试有Fragment,因为我不具备的机器人:configChanges ="方向"在我的Android Manifest.

android android-fragments

14
推荐指数
2
解决办法
1万
查看次数

API级别29中不推荐使用Environment.getExternalStorageDirectory()

在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)

android deprecated android-api-levels

14
推荐指数
7
解决办法
6338
查看次数

在主发射器强制停止后未收到Android AppWidget的按钮单击事件

我有一个应用程序小部件,可以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)

java android android-widget

12
推荐指数
1
解决办法
412
查看次数

对于低于23的API,图层列表中的形状可绘制不正确

昨天,我已切换到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)上运行应用程序时,我也得到了正方形.

以防这有用:

  • compileSdkVersion 23
  • buildToolsVersion"23.0.3"
  • minSdkVersion 11
  • targetSdkVersion 23
  • 没有什么用于buildType调试
  • 依赖项:编译'com.android.support:appcompat-v7:23.0.1'
  • Activity延伸AppCompatActivity

我认为这个问题在某种程度上关系到使用的top,left,rightbottom为上层.因为如果我只是在一个正方形的顶部放置一个圆圈,预览以及"真实的东西"将按预期的方式对所有API级别起作用.

编辑我也开始了一个全新的项目,使用相同的代码/ xml和以下(自动创建)build.gradle:

  • compileSdkVersion 24
  • buildToolsVersion"24.0.2"
  • minSdkVersion 15
  • targetSdkVersion 24
  • 没有什么用于buildType调试
  • 依赖项:编译'com.android.support:appcompat-v7:24.2.0'
  • Activity延伸 …

android layer-list android-studio android-shapedrawable

10
推荐指数
1
解决办法
8336
查看次数

带有多个倒计时器的Recyclerview会导致闪烁

我想表明我的每个单元格内剩下多少时间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)

android countdowntimer android-recyclerview

8
推荐指数
1
解决办法
7083
查看次数

我所有的布局xml文件都变成了自动生成的文件

昨天,我的应用程序上的所有内容均正常运行,但今天,当我打开Android Studio时,所有xml文件均已损坏(?-不确定这是否正确)

每个人都是这样

在此处输入图片说明

java xml android android-layout android-studio

8
推荐指数
1
解决办法
386
查看次数