对Kindle Fire的RelativeLayout的不工作设置页边距 [英] Setting margins on RelativeLayout doesnt work on Kindle Fire

查看:280
本文介绍了对Kindle Fire的RelativeLayout的不工作设置页边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是类似于我的<一个href=\"http://stackoverflow.com/questions/9811722/setting-margins-on-relative-layout-doesnt-work\">$p$pvious问题但它没有与Kindle Fire的工作(2.3.4)。结果
我用了一个FragmentTransaction一个片段加入到一个的FrameLayout。我想动态改变的RelativeLayout由片段中的余量。

然而,利润率不与对Kindle Fire的FrameLayout.layoutParams改变。然而,这适用于3.2.1。我用setMargins(),也试了一下没有工作。

有谁知道我可以动态改变对Kindle Fire的利润率?

 公开查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState){        查看查看= inflater.inflate(R.layout.infocard,集装箱,FALSE);        RelativeLayout的infoLayout =(RelativeLayout的)view.findViewById(R.id.info);
        infoLayout.setOnClickListener(新EmptyClickListener());        最终诠释宽度= 250;
        最终诠释高= 270;
        INT LEFTMARGIN = 0;
        INT TOPMARGIN = 0;
        FrameLayout.LayoutParams PARAMS =新FrameLayout.LayoutParams(宽度,高度);        如果(X - 宽度小于0){
            LEFTMARGIN = 0;
        }其他{
            LEFTMARGIN = X - 宽+ 40;
        }        如果(Y&GT; = 400安培;&安培; Y&LT; = 480){
            TOPMARGIN = 160;
        }        params.leftMargin = LEFTMARGIN;
        params.topMargin = TOPMARGIN;        //params.setMargins(leftMargin,TOPMARGIN,0,0); //这个没有工作或者
        infoLayout.setLayoutParams(PARAMS);        TextView的titleview的=(TextView中)view.findViewById(R.id.titleCard);
        titleView.setText(职称);        返回视图。
    }


解决方案

好吧,我能够在另一个RelativeLayout的包装我infoLayout来解决这个问题,现在它完美的作品

This is similar to my previous question but it didnt work with the Kindle Fire (2.3.4).
I used a FragmentTransaction to add a Fragment into a FrameLayout. I want to dynamically change the margin of the RelativeLayout used by the Fragment.

However, the margins are not changing with FrameLayout.layoutParams on the Kindle Fire. However, this works on 3.2.1. I also tried using setMargins() and it didnt work.

Does anyone know how I can dynamically change the margins on the Kindle Fire?

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.infocard, container, false);

        RelativeLayout infoLayout = (RelativeLayout) view.findViewById(R.id.info);
        infoLayout.setOnClickListener(new EmptyClickListener());

        final int width = 250;
        final int height = 270;
        int leftMargin = 0;
        int topMargin = 0;
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(width, height);

        if (x - width < 0) {
            leftMargin = 0;
        } else {
            leftMargin = x - width + 40;
        }

        if (y >= 400 && y <= 480) {
            topMargin = 160;
        }

        params.leftMargin = leftMargin;
        params.topMargin = topMargin;

        //params.setMargins(leftMargin, topMargin, 0, 0); //this didnt work either
        infoLayout.setLayoutParams(params);

        TextView titleView = (TextView) view.findViewById(R.id.titleCard);
        titleView.setText(title);

        return view;
    }

解决方案

Ok I was able to fix this by wrapping my infoLayout in another RelativeLayout, and now it works perfectly

这篇关于对Kindle Fire的RelativeLayout的不工作设置页边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆