小编Geo*_*_BJ的帖子

Android:如何使水平线性布局中的2个按钮之间没有空格

我刚刚发现我无法删除,即使我设置了2个按键之间的空间layout_marginRightlayout_marginLeft下面.但是如果我将空间设置得更大,例如10 dp,那就更有意义了.有什么方法可以解决吗?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:orientation="horizontal" android:padding="0dp"
    android:layout_height="wrap_content" android:gravity="fill_horizontal" android:layout_margin="0dp">
    <Button android:id="@+id/LocationTitleButton"
                    android:layout_width="wrap_content" 
                    android:layout_height="wrap_content"
                    android:layout_marginRight="0dp"
                    android:layout_gravity="center_vertical" 
                    android:layout_weight="1"
                    android:ellipsize="end" 
                    android:gravity="center_vertical"
                    android:scrollHorizontally="true" 
                    android:singleLine="true"
                    android:text="Add location" 
                    android:textStyle="bold" />
                <Button android:textColor="#FF000000" 
                    android:layout_weight="0" 
                    android:id="@+id/AddLocationButton" 
                    android:text="Search" 
                    android:gravity="center_vertical"
                    android:layout_gravity="center_vertical" 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                    android:layout_marginLeft="0dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android space button android-linearlayout

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

Android:如何设置ImageButton的src图像的高度/宽度?

Android:如何设置ImageButton图像的高度/宽度(src图像背景的内容)?

我想设置顶层图像(不是背景)图像的高度/宽度,应该自定义图像的大小而不是自动填充按钮

android imagebutton

14
推荐指数
3
解决办法
6万
查看次数

如何使Android Button的drawableLeft保持旋转?

我需要创建一个按钮,左边有一个图标,右边有一个文本.按下按钮后,我想在按钮左侧图标的位置看到旋转图像的动画.

我知道如何使用ImageView旋转图像,但它对我当前的要求没有帮助.

我试图使用AnimationDrawable,但它也没有用,没有动画但只显示了第一个png文件.无论我使用什么背景或leftDrawable按钮来运行AnimationDrawable都是一样的.代码如下:

package com.example.layout;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.Button;

public class TestLinearlayoutActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    public void onStart() {
        super.onStart();

        Button locationTitleButton = (Button) findViewById(R.id.LocationTitleButton);
        //locationTitleButton.setBackgroundResource(R.drawable.loading);

        locationTitleButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.loading, 0, 0, 0);

        Drawable[] locationTitleButtonDrawables = locationTitleButton.getCompoundDrawables();
        AnimationDrawable animDrawable = (AnimationDrawable) locationTitleButtonDrawables[0];
        //AnimationDrawable animDrawable = (AnimationDrawable) locationTitleButton.getBackground();
        animDrawable.start();
    }
}

//loading.xml:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">

    <item …
Run Code Online (Sandbox Code Playgroud)

android rotation button

6
推荐指数
1
解决办法
4479
查看次数

Robolectric:NotFoundException:org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:258)中的未知资源0

我在测试apdater的getView时遇到了错误.测试代码在测试用例期间调用View.setImageResource(0)以在异常发生时设置空图像.

我用Eclipse运行了测试robolectric-2.2-20130712.161723-17-jar-with-dependencies.jar.我尝试用ShadowResources.createFor(new ResourceLoader(){...}替换ResouceLoader.但是它不起作用.我没有调用我替换的ResouceLoader.

有人知道怎么解决吗?

android.content.res.Resources$NotFoundException: unknown resource 0
at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:258)
at org.robolectric.shadows.ShadowAssetManager.getResourceValue(ShadowAssetManager.java:85)
at android.content.res.AssetManager.getResourceValue(AssetManager.java)
at android.content.res.Resources.getValue(Resources.java:1009)
at android.content.res.Resources.getDrawable(Resources.java:658)
at org.robolectric.shadows.ShadowView.buildDrawable(ShadowView.java:92)
at org.robolectric.shadows.ShadowImageView.setImageResource(ShadowImageView.java:38)
at android.widget.ImageView.setImageResource(ImageView.java)
at com.mobile.client.share.edentity.PhotostreamAdapter.getView(PhotostreamAdapter.java:54)
at com.mobile.client.share.edentity.PhotostreamAdapterTest.testGetView(PhotostreamAdapterTest.java:163)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:241)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Run Code Online (Sandbox Code Playgroud)

我的Apdater ContentDetailsAdapter上的roboletric单元测试中的另一个类似问题来自语句mContext.getResources().getString(R.string.delete_hint_title).mContext由Robolectric.getShadowApplication().getApplicationContext()创建.关于Roboletric我的配置有问题吗?我能够在单元测试中调用ProgressDialog.show(mContext,"","").似乎问题总是与资源有关.这是堆栈:

android.content.res.Resources$NotFoundException: String resource ID …
Run Code Online (Sandbox Code Playgroud)

android unit-testing

4
推荐指数
1
解决办法
2885
查看次数