LayoutParams of custom ViewGroup not showing in android studio editor

I have a class that extends LinearLayout

- it is almost identical, it is just slightly different.

public class CustomLinearLayout extends LinearLayout {
    <Standard constructors...>

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        <Custom measuring code here>
    }
}

      

This works great, but now none of the children show ANY LinearLayout LayoutParams attributes in the properties of the layout editor in Android Studio, even something like layout:width

.

My guess is that LayoutParams are not inherited, so I just duplicated LinearLayout.LayoutParams

and added it everywhere, that is:

public class CustomLinearLayout extends LinearLayout {
    public static class LayoutParams extends LinearLayout.LayoutParams {

        public LayoutParams(Context c, AttributeSet attrs) {
            super(c, attrs);
        }

        public LayoutParams(int width, int height) {
            super(width, height);
        }

        public LayoutParams(int width, int height, float weight) {
            super(width, height, weight);
        }

        public LayoutParams(ViewGroup.LayoutParams p) {
            super(p);
        }

        public LayoutParams(MarginLayoutParams source) {
            super(source);
        }

        public LayoutParams(LinearLayout.LayoutParams source) {
            super(source);
        }
    }

    @Override
    public LayoutParams generateLayoutParams(AttributeSet attrs) {
        return new LayoutParams(getContext(), attrs);
    }

    @Override
    protected LayoutParams generateDefaultLayoutParams() {
        return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    }

    @Override
    protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
        return new LayoutParams(p);
    }

    @Override
    protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
        return p instanceof LayoutParams;
    }

      

And, in attrs.xml:

<declare-styleable name="com.domain.package.CustomLinearLayout_Layout">
    <attr name="layout_width" format="dimension">
        <enum name="fill_parent" value="-1" />
        <enum name="match_parent" value="-1" />
        <enum name="wrap_content" value="-2" />
    </attr>
</declare-styleable>

      

Here is the layout view:

<?xml version="1.0" encoding="utf-8"?>

<com.domain.package.CustomLinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

      

Basically as a test to see if it works. However, nothing appears in the editor. I compiled the project and tried it declare-styleable

with and without the full package name. What am I missing?

(EDIT: just to clarify the end goal - I want the attributes to LinearLayout.LayoutParams

be visible in the Android Studio editor). I was hoping they were inherited automatically, but since they are not, I'm trying to duplicate them by subclassing LinearLayout.LayoutParams

, but that won't work either. If there is a way to just inherit LinearLayout

styleables, that would be preferable.)

+3
android android-layout android-studio


source to share


No one has answered this question yet

Check out similar questions:

1345
Where can I put the "assets" folder in Android Studio?
1214
Rename package in Android Studio
1206
What is Gradle in Android Studio?
1112
What should my Android Studio .gitignore project be?
1005
How to "select Android SDK" in Android Studio?
947
Android Studio: add jar as library?
784
How do I add a library project to Android Studio?
753
Code formatting shortcut in Android Studio
733
What is the shortcut to automatically import everything in Android Studio?
690
"cannot resolve R character" in Android Studio



All Articles
Loading...
X
Show
Funny
Dev
Pics