2

I am having this error android.widget.LinearLayout$LayoutParams.

When using this code.

public void modifyingTextViews(){//This sets up a margin for the textviews.
        LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
        llp.setMargins(0, 30, 0, 30);
        textview1.setLayoutParams(llp);
        textview2.setLayoutParams(llp);
    }

It conflicts with my touch methods or my load methods which consists of view flipper with 2 textview and a loader.

From what I understand from a guy with a similar issue is that it is because I am getting this error probably because of the arrangement of the view.

Now My question is how would I be able to tell which is my main view on a view flipper if I have different xmls. Also if there would be a quick fix to the problem that would be appreciated as well.

1
  • in the future, it'd be a good idea to display your stack trace and/or logcat output so we can know exactly what the problem is... Commented Jan 19, 2012 at 16:19

1 Answer 1

1

I can't tell what the issue is without knowing more (your xml code would be a start). Since you asked for an easy fix... I would just define everything in XML. That way everything is organized and you don't have to worry about setting LayoutParams at runtime.

<ViewFlipper android:id="@+id/flipper"
    android:layout_width="match_parent" 
    android:layout_height="match_parent">

    <!-- layout #1 -->
    <LinearLayout android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TextView android:id="@+id/textview1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <!-- layout #2 -->
    <LinearLayout android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TextView android:id="@+id/textview2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <!-- fill in the rest here -->

</ViewFlipper>

Of course, this is a hypothetical example and you'll have to write the XML code to get the layout you want, but hopefully this gives you a good idea of where to start. Once you get it all set up, initializing the layout is simply a matter of calling setContentView() in your onCreate() method.

Sign up to request clarification or add additional context in comments.

1 Comment

in my experience it's a lot harder to make mistakes when you code your layout in XML, rather than creating them dynamically at runtime :). glad it worked for you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.