1

I want to add view & rotate it by 90 degree programmatically, however I can't figure how to set its dimensions properly.

This is my placeholder:

        <FrameLayout
            android:layout_width="40dp"
            android:layout_height="match_parent"
            android:id="@+id/placeholder"
            android:orientation="vertical"
            android:background="@color/green"
            android:layout_weight="1">

And this is how my code looks like:

    FrameLayout placeholderView = (FrameLayout) findViewById(R.id.placeholder);

    View myView = new View(getApplicationContext());
    myView.setBackgroundColor(Color.RED);
    myView.setRotation(90);
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    myView.setLayoutParams(layoutParams);
    placeholderView.addView(myView);

The result is that BOTH width & height get the same value, so the view looks like this:

enter image description here

While I wanted it to expand on entire height of its parent.

salih kallai
  • 879
  • 2
  • 13
  • 34
Tamir
  • 625
  • 1
  • 12
  • 27

1 Answers1

1

ViewGroup.LayoutParams.FILL_PARENTHello can you please try this instead of this:

myView.setRotation(90);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)

try this:

Remove setRotation

FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
Ashwini Bhat
  • 500
  • 1
  • 4
  • 17
  • I cannot remove setRotation. I know it doesn't make sense to rotate a view as in my code, I just simplified my code to demonstrate the problem I have. I also noticed that FILL_PARENT is deprecated. – Tamir Apr 25 '16 at 07:33
  • you need vertical view right? i tried on my system working fine and i removed setRotation..even u can try on XML – Ashwini Bhat Apr 25 '16 at 07:39
  • I want to use vertical SeekBar so I must rotate it. – Tamir Apr 25 '16 at 08:12
  • http://stackoverflow.com/questions/18395064/android-vertical-seek-bar-like-google-play-music-app check this link – Ashwini Bhat Apr 25 '16 at 08:21
  • Thanks. I already checked many solutions for vertical SeekBar, none of them worked properly with RTL support. I will check also this one. But I wondered if there's a solution to the general problem I posted, not specfically for SeekBar, it looks like a very basic functionality that should be supported in Android (rotating views), and could be useful also in my case. – Tamir Apr 25 '16 at 08:41