小编Dav*_*vid的帖子

Android在运行时更改谷歌地图填充

我想在运行时移动谷歌地图布局项目,但我无法做到这一点,我不知道它是否可能.我想要做的是:我有一个谷歌地图片段占据了所有的屏幕.我也有广告.当应用程序启动时,我会显示地图.像这样:

在此输入图像描述

加载广告后,我会在底部展示广告,但我需要在广告上方移动Google徽标.像这样:

在此输入图像描述

我尝试过:

if (banner is loaded)
googleMap.setPadding(0, 0, 0, banner.getLayoutParams().height);
Run Code Online (Sandbox Code Playgroud)

但我没有成功.我究竟做错了什么?

编辑:感谢@SimplePlan,我更改了RelativeLayout,其中包括mapfragment到FrameLayout:

<FrameLayout >
    <fragment
        android:id="@+id/map"
        class="com.google.android.gms.maps.SupportMapFragment" />

    <com.inmobi.monetization.IMBanner
        android:layout_gravity="bottom" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

我在广告中添加了一位听众:

banner.setIMBannerListener(new IMBannerListener() {
    @Override
    public void onBannerRequestSucceeded(IMBanner arg0) {
        googleMap.setPadding(0, 0, 0, banner.getLayoutParams().height);
    }
});
Run Code Online (Sandbox Code Playgroud)

android google-maps padding inmobi

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

CollapsingToolbarLayout在API 26中显示图像下的条形图

将支持库从v25.4.0升级到v26.0.0后,CollapsingToolbarLayout它不适合内部的内容,但在下面显示一个空白区域(可能是状态栏的大小).为了显示:

使用v25.4.0:

随着v25.4.0

随着v26.0.0:

随着v26.0.0

那个XML布局Activity

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:titleEnabled="false">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                android:src="@drawable/material_flat"
                android:scaleType="fitXY"
                app:layout_collapseMode="parallax" />

            <ImageView
                android:layout_width="86dp"
                android:layout_height="86dp"
                android:layout_gravity="bottom|start"
                android:paddingBottom="16dp"
                android:paddingLeft="16dp" />


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin" />
        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>


    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Minions ipsum ..." />

    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

我试过玩这个android:fitsSystemWindows值,正如这里所建议的,但结果不是预期的.如果你想查看更多细节,我的实现代码就是这个Github repo …

android android-collapsingtoolbarlayout

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

LibGDX - 在tile/tilemaps中的纹理上的文本

有没有办法将文本放在Tilemaps中的纹理上?

我在基于棋子的游戏中工作,我需要在一个瓷砖中显示有多少棋子.我使用TiledMap加载电路板.我的代码如下:

GameScreen.java

public class GameScreen implements Screen {

private TiledMap board;

public GameScreen(final MyGame gam) {

   board = new TmxMapLoader().load("maps/tablero-64.tmx");
   renderer = new OrthogonalTiledMapRenderer(board, 1/64f);

   boardCamera = new OrthographicCamera();
   boardCamera.setToOrtho(false, WIDTH, HEIGHT);
   boardCamera.position.set(CENTERX, CENTERY, 0);

   // Added this to avoid continuous rendering
   Gdx.graphics.setContinuousRendering(false);
   Gdx.graphics.requestRendering();
}

@Override
public void render(float delta) {
   boardCamera.update();
   renderer.setView(boardCamera);
   renderer.render();
   renderer.getSpriteBatch().begin();
   for (Stack checker : whiteCheckers) checker.draw(renderer.getSpriteBatch(), 1);
   for (Stack checker : blackCheckers) checker.draw(renderer.getSpriteBatch(), 1);
   renderer.getSpriteBatch().end();
}
}
Run Code Online (Sandbox Code Playgroud)

Stack.java

public class Stack extends Actor { …
Run Code Online (Sandbox Code Playgroud)

java android libgdx

5
推荐指数
1
解决办法
1556
查看次数

使用Robolectric和Gradle测试资源文件夹

我想将一些测试文件添加到我的测试文件夹中,因为我想模拟一些JSON文件加载.问题是最后的Robolectric版本(2.4)看起来没有找到测试资源路径(我得到了NPE),但是使用Robolectric 2.3就可以了.

这就是我的项目的样子:

在此输入图像描述

在Res类(由测试使用)中,我以这种方式加载JSON:

public static String str(String path) throws IOException {
    InputStream is = null;
    try {
        is = Res.class.getResourceAsStream(path); // "is" IS NULL!
        return new String(ByteStreams.toByteArray(is)); // ERROR HERE
    } finally {
        if (is != null) {
            is.close();
        }
    }
}

public static JsonReader json(String path) throws IOException {
    return new JsonReader(new StringReader(str("/contact.json")));
}
Run Code Online (Sandbox Code Playgroud)

那是我的build.gradle文件:

buildscript {
    // ...
    dependencies {
        classpath 'org.robolectric:robolectric-gradle-plugin:1.0.1'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'org.robolectric'

robolectric {
    // ...
    include '**/*Test.class'
    ignoreFailures …
Run Code Online (Sandbox Code Playgroud)

android json robolectric android-resources

5
推荐指数
1
解决办法
1917
查看次数

使用Espresso单击EditText的drawable右键

怎么可能点击EditText的右侧drawable(查看截图)?我尝试了几种方法但总是卡住了.

public static Matcher<View> withEditTextDrawable(final int resourceId) {
    return new BoundedMatcher<View, EditText>(EditText.class) {
        @Override
        protected boolean matchesSafely(final EditText editText) {
            // ????

            return false;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("with drawable from resource id: ");
            description.appendValue(resourceId);
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

android android-edittext android-drawable android-espresso

5
推荐指数
2
解决办法
3526
查看次数