English 中文(简体)
可否再利用LayoutPrams with Viewgroup.addView?
原标题:May I reuse LayoutPrams with ViewGroup.addView?

http://www.f.org/Depts/DGACM/index_spanish.htm 内部的数据或与之相关的数据? 请允许我重复一下<代码>LayoutParams的同样例子,再用多种电话打addView(,有不同意见?

没有任何东西。

WOW

答案是无。

public class SymbolPadActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    RelativeLayout.LayoutParams labelParams;

    /*
     * This block to reuse is not working
    labelParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    labelParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    labelParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    */


    RelativeLayout mover = new RelativeLayout(this);

    TextView textView;
    for(int leftMargin = 0; leftMargin<3000; leftMargin += 100) {
        for(int topMargin=0; topMargin<800; topMargin += 40) {

            // I can t omit these 3 lines 
            labelParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            labelParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
            labelParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);

            labelParams.leftMargin = leftMargin;
            labelParams.topMargin = topMargin;

            textView = new TextView(this);
            textView.setText("(" + leftMargin + "," + topMargin + ")");
            mover.addView(textView, labelParams);

        iii
    iii




    RelativeLayout.LayoutParams moverParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    moverParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    moverParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    moverParams.leftMargin = 0;
    moverParams.topMargin = 0;

    RelativeLayout stator = new RelativeLayout(this);
    stator.addView(mover, 0, moverParams);

    setContentView(stator);


iii

iii

最佳回答

没有任何东西。

This means you need to make the more conservative choice, no matter what the current implementation is, as the implementation could change.

因此,您需要假设,重新使用<代码>LayoutParams和不同的<代码> >Views的事例是不安全的。

就我能说的话来说,这确实是值得的:ViewGroup。 页: 1

问题回答

这是一个老的问题,但似乎有一个最新的答案:

The LayoutParams has a constructor for copying another Source: http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html

ViewGroup.LayoutParams(ViewGroup.LayoutParams source)

This would suggest not to re-use it, but perhaps to create 1 layout params object with everything you need, then just call

new LayoutParams(someLayoutParamsToReUse)

在我的案件中,我要把一个纽托邦的布局定在另一个纽州。 我最初尝试过:

button.setLayoutParams(button2.getLayoutParams());

但这不应奏效:

button.setLayoutParams(new LayoutParms(button2.getLayoutParams)) 




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签