JVS
JVS

Reputation: 2682

Set Layout Params for custom View

In XML I was creating a new Entity of SwipeDeck (customView) like this :

<com.daprlabs.aaron.swipedeck.SwipeDeck
 android:id="@+id/swipe_deck"
 android:layout_width="match_parent"
 android:layout_height="20dp"
 swipedeck:card_spacing="15dp"
 swipedeck:max_visible="1"
 swipedeck:render_above="true"
 swipedeck:swipe_enabled="true">

Now I am trying to programmatically set the x and y position. this works fine:

cardStack = (SwipeDeck) findViewById(R.id.swipe_deck);

    cardStack.setX(20);
    cardStack.setY(10+actionBarHeight);

When I am trying to set the height and width dynamically, nothing happens:

cardStack = (SwipeDeck) findViewById(R.id.swipe_deck);
    ViewGroup.LayoutParams params = cardStack.getLayoutParams();
    params.height=500;
    params.width =  screen_width - 40;
    cardStack.setLayoutParams(params);

Everything happens in onCreate. Any ideas?

Upvotes: 0

Views: 2382

Answers (1)

sd ss
sd ss

Reputation: 26

You should be declaring "params"'s type with respect to the ViewGroup that contains it.
For example, replace the line

ViewGroup.LayoutParams params = cardStack.getLayoutParams();  

with

LinearLayout.LayoutParams params = cardStack.getLayoutParams();  

if your custom view is inside a LinearLayout

Upvotes: 1

Related Questions