相关疑难解决方法(0)

Android中状态栏的高度

Android中状态栏的高度是多少?总是一样的吗?

根据我的测量结果,它似乎是25dp,但我不确定它是否在所有平台上具有相同的高度.

(我想知道这是为了正确实现从没有状态栏的活动到执行状态栏的活动的淡入淡出过渡)

android statusbar

314
推荐指数
16
解决办法
33万
查看次数

带支持库的FloatingActionButton示例

最近,我读了这些帖子:

Android设计支持库

Android支持库,修订版22.2.0

FloatingActionButton

但是,他们都没有给我一个关于创建新的详细示例FloatingActionButton.很难理解,我问这个问题.

谁能给我一个关于它的例子?

任何帮助都很值得赞赏.提前致谢.

编辑

我刚刚在FloatingActionButton(FAB)上发现了一些问题,我想改进另一个答案.请参阅下面的答案.

android android-support-library floating-action-button android-design-library

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

OnGlobalLayoutListener:弃用和兼容性

我必须使用一个OnGlobalLayoutListener对象,然后删除监听器,我有一个问题与我用以下代码解决的弃用方法.

protected void onCreate(Bundle savedInstanceState) {
    final LinearLayout llTotal = (LinearLayout) findViewById(R.id.mmc_ll);
    ViewTreeObserver vto = llTotal.getViewTreeObserver();
    if(vto.isAlive()){
        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                //
                // mycode
                //
                if (Build.VERSION.SDK_INT<16) {
                    removeLayoutListenerPre16(llTotal.getViewTreeObserver(),this);
                } else {
                    removeLayoutListenerPost16(llTotal.getViewTreeObserver(), this);
                }
            } 
        });
    }
    super.onCreate(savedInstanceState);
}

@SuppressWarnings("deprecation")
private void removeLayoutListenerPre16(ViewTreeObserver observer, OnGlobalLayoutListener listener){
    observer.removeGlobalOnLayoutListener(listener);
}

@TargetApi(16)
private void removeLayoutListenerPost16(ViewTreeObserver observer, OnGlobalLayoutListener listener){
    observer.removeOnGlobalLayoutListener(listener);
}
Run Code Online (Sandbox Code Playgroud)

这是对的吗?有更好的方法来处理兼容性?

使用API​​ 10在模拟器中运行代码我在LogCat中有以下警告

04-24 09:30:12.565: I/dalvikvm(471): Could not find method android.view.ViewTreeObserver.removeOnGlobalLayoutListener, referenced from method com.my.project.ActivityHome.removeLayoutListenerPost16
04-24 …
Run Code Online (Sandbox Code Playgroud)

compatibility android deprecated

72
推荐指数
5
解决办法
4万
查看次数

Android中的渐变文字

如何扩展TextView以允许绘制具有渐变效果的文本?

user-interface android

56
推荐指数
5
解决办法
3万
查看次数

以编程方式获取布局的高度和宽度

我已经设计在其中的布局LinearLayout有2个孩子LinearLayout,并FrameLayout和每个孩子,我把不同的意见.

我只想测量高度和宽度,FrameLayout这样我才能达到我的目的.

在我正在使用的程序中

int height,width;

FrameLayout fr=(FrameLayout)findviewbyid(R.id.fr);
height=fr.getHeight();
width=fr.getWidth();
Run Code Online (Sandbox Code Playgroud)

返回0两者的 值

即使我尝试使用以下代码int height,width;

FrameLayout fr=(FrameLayout)findviewbyid(R.id.fr);
height=fr.getMeasuredHeight();
width=fr.getMeasuredWidth();
Run Code Online (Sandbox Code Playgroud)

返回相同的值 0

最后我尝试使用以下代码,int height,width;

FrameLayout fr=(FrameLayout)findviewbyid(R.id.fr);
height=fr.getgetLayoutParams().height();
width=fr.getLayoutParams().width;
Run Code Online (Sandbox Code Playgroud)

返回我-2-1

我希望解决方案以编程方式获取任何布局的高度和宽度?

android android-layout

50
推荐指数
9
解决办法
8万
查看次数

如果我在onResume中为布局调用getMeasuredWidth()或getWidth(),则返回0

如果我在onResume中为布局调用getMeasuredWidth()或getWidth(),则返回0.我认为此时此视图尚未显示.

另外我认为我需要在绘制布局后调用的回调方法中放置getMeasuredWidth()或getWidth(),并且已知视图测量.我应该使用什么android回调方法?

layout android measurement

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

如何在渲染之前获取textview的行数?

如何在TextView呈现字符串之前获取字符串将占用的行数.

A ViewTreeObserver不起作用,因为它们仅在渲染后触发.

java android textview android-layout

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

onCreate中的LinearLayout高度为0

我正在尝试根据(屏幕高度 - 我的布局高度)/ list.size动态调整行的高度.

不幸的是,在onCreate方法中,布局高度返回null(当我在单击侦听器中调用它时不是这样).

还有其他方法我可以称之为吗?

android

22
推荐指数
1
解决办法
9792
查看次数

view.getViewTreeObserver().addOnGlobalLayoutListener泄漏片段

当我使用它GlobalLayoutListener来查看softKeyboard是否被打开时,片段在被销毁后不再是garbageCollected.

我所做的:

  • 我删除了onDestroy()片段中的监听器
  • 我的监听器设置为nullonDestroy()
  • 我将观察到的视图设置为null onDestroy()

仍在泄漏碎片.

有没有人有类似的问题,并知道它的修复?

我的onDestroy:

   @Override
public void onDestroy(){
    Log.d(TAG , "onDestroy");

    if(Build.VERSION.SDK_INT < 16){
        view.getViewTreeObserver().removeGlobalOnLayoutListener(gLayoutListener);
    }else{
        view.getViewTreeObserver().removeOnGlobalLayoutListener(gLayoutListener);
    }

    view = null;
    gLayoutListener = null;



    super.onDestroy();
    }
Run Code Online (Sandbox Code Playgroud)

android memory-leaks android-fragments

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

绑定视图以在RelativeLayout中拖动

在RelativeLayout中创建了一个可拖动的视图.但它似乎超越了RelativeLayout.

我只想在ViewGroup中创建一个View draggable

这个观点是draggable根据Screen.它可以超越RelativeLayout的界限.我如何限制它在RelativeLayout中保持可拖动.

CustomImageButton

public class ImageButtonCustom extends ImageButton implements View.OnTouchListener{

    float dX, dY;

    private RelativeLayout rootView;
    private ImageButtonCustom imageButtonCustom;
    private OnMoveListener onMoveListener;

    public ImageButtonCustom(Context context,RelativeLayout rootView){
        super(context);
        this.rootView = rootView;
        init();

    }
    public ImageButtonCustom(Context context) {
        super(context);
        init();
    }

    public ImageButtonCustom(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public ImageButtonCustom(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        imageButtonCustom = this;
        setImageResource(R.drawable.upper_left);
        setBackgroundColor(Color.TRANSPARENT);
        setOnTouchListener(this);

        /*RelativeLayout.LayoutParams …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view ontouchlistener android-relativelayout

9
推荐指数
1
解决办法
4209
查看次数