Android – How can I Move a Layout Partially Offscreen? - java

I am trying to make a sliding menu in an android application I am building for my school, and whenever I open the menu, the menu button, in addition to the other views I've tried, are scaled to fit in the remaining 25% of the layout still on the screen. So my question is, how can I disable this scaling so views can be moved offscreen along with their parent layout?
This is the XML file of the layout I am trying to move. It contains the misbehaving button:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/background_color"/>
<ImageButton
android:id="#+id/menu_button"
android:layout_width="56dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:background="#drawable/menu_button"/>
</RelativeLayout>
This is what the menu looks like closed:
This is how it looks when opened:
And this is how I want it to be when opened. Notice the menu button has moved offscreen.
Any help is appreciated.
EDIT:
Although it may work for a single button, I do not want to make the views invisible, I would like to move them off the screen to the right. If, for example, I wanted to add a TextView that fills a horizontal row on the layout, the TextView would be scaled to 25% of the screen upon opening the menu. Instead, I want it to retain the size and shape of all views and make them move partially off screen.

When menu opens up, set the visibility of menu icon to GONE
icon.setVisibilty(View.GONE);
and when close , again set visibility of icon to VISIBLE.
icon.setVisibilty(View.VISIBLE);

Related

How to define custom margins to StepperLayout navigation buttons

I have a StepperLayout that displays a list of questions to the users. However, half of the "NEXT" navigation button is hidden after giving it a background color. I want to define custom margins and alignments to the navigation buttons. See the gif image below.
I have tried overriding the codes used for the NEXT and BACK button but that displays duplicate buttons. I have also tried adding some paddings to the StepperLayout but still, it didn't help.
<com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/stepper"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:ms_activeStepColor="#color/stepper_btn_blue"
app:ms_nextButtonBackground="#color/stepper_btn_blue"
app:ms_backButtonColor="#000000"
app:ms_completeButtonColor="#color/colorWhite"
app:ms_completeButtonText="Finish"
app:ms_stepperType="tabs"
tools:theme="#style/AppTheme" />

Tips horizontal scroll with textbox

I would like to make horizontal swipe scroll with images and text views on it, 3-4 views.
Like tips screen on applications.
But, don't know which component to use, I need something like tabs(3-4 different layouts) but I dont want to show tab menu up. Just full screen, few buttons down, and in middle textbox with tip(which i want to animate later), everything is same in every layout just different image and text.
No code here in question because i stuck on beginning and need few tips what to use or some linked tutorial.
Here is how you can do this.
<ViewFlipper
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pro_flip"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
//put your child elements for first page on this layout
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
//put your child elements for second page on this layout
</LinearLayout>>
</ViewFlipper>
Content on the first layout will be visible to the user at first, when he swipes the next layout will be loaded.
ViewFlipper should be sufficient for simple content like you mentioned. If you want something more look into ViewPager.

How to create fixed layout in Android

My activity has spinners, which supposedly should be in the centre. Relative to the spinners positions, buttons and labels are placed.
Another activity has 8 buttons in which certain values will be displayed. I have used a RelativeLayout in all activities. My app works well on my Moto G, but on bigger devices, the alignment of all the buttons and spinners changes.
I want to fix that issue.
Use this in the case of RelativeLayout
android:layout_centerInParent="true"
This will make the element always stick to the center of the device irrespective of the size of the device. Try it..
eg:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton android:id="#+id/btnSample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"></ImageButton>
</RelativeLayout>

Android: Fixed size ScrollView not scrolling/scrolling weird

I have a problem with a fixed size scrollview that i'm trying to make. I've read many questions that are similar (but not equal) to mine here in StackOverflow and other sites and none of the answers have helped me, so I decided to ask my own question.
Basically, i want a fixed size scrollview with different controls inside. The basic one would be a textview of a dynamically changing size inside it. When I change the text of the textview and it is bigger than the scrollview, the scrollbars flash quickly, as they should, indicating that I can scroll but no matter how many times I swipe my finger, it doesn't scroll. Then I tried swiping with two or three fingers and sometimes (only a counted number of times) it scrolls.
I have tried many different approaches to this, like changing the textview to an edittext with focusable = false so it doesn't give the user chance to edit the text; or putting the textview alone in the scrollview, or wrapping it in linearlayouts, relative layouts etc. and it still doesnt scroll.
Below is the code as it is today. This scrollview is inside a vertical linearlayout along with other controls that I'm not putting 'cause of the length, but if someone needs it, I'll put it. I would appreciate very much if someone can point to my problem or help me solving this.
XML:
<ScrollView
android:id="#+id/scrollFifthHorizontalLineDetails"
android:layout_width="304dp"
android:layout_height="133dp"
android:layout_gravity="center"
android:layout_marginTop="5dp" >
<LinearLayout
android:id="#+id/rrrr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/txtlblPlaceDetails"
android:layout_width="302dp"
android:layout_height="wrap_content"
android:background="#drawable/placedescriptionbg"
android:text="#string/null_text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</ScrollView>
the line in which I populate the TextView:
((TextView) findViewById(R.id.txtlblPlaceDetails)).setText(mJsonOb.getString("placeDescription"));
I had a similar problem with an Android app I was developing a few months back. I got around the scrolling problem by increasing the layout width for the scroll view. In the editor you can actually drag the RHS of the scroll view to exceed the visible area. I think I set the android:layout_width to about 1024.

Android SDK HorizontalScrollView

This is the layout of my app, I will want both the album and the songs (Red & Blue) to move horizontally as you scroll to view different albums (Purple). However, I want the songs (Blue) to move independently vertically to scroll through the songs in the album.
So far my coding looks as you would expect...
<LinearLayout
<HorizontalScrollView
<LinearLayout
<LinearLayout (This layout is so the album cover is displayed correctly)
<ImageView
<ScrollView
<LinearLayout
<TextView (Songs)
<TextView
<TextView
<TextView
My problem occurs when I vertically scroll through the songs. when I scroll vertically, if I move my finger to the left or the right it detects the HorizontalScrollView and stops scrolling vertically. What can I do to stop this? If there is nothing I can do, what else except HorizontalScrollView could I use?
Thanks,
-Steven
I would say fundamentally you need to change your layout. First off, each album will have a different number of songs, so the list of songs would be best done as a ListView as opposed to hand built ScrollView. Next, for the album, I would use a ViewPager and attach a ViewPager#OnPageChangeListener to it and when the page is changed the list of songs are updated.
Now to fix your current xml, and based on my understanding that you only want the Album to be moving left to right you need to do this:
<LinearLayout
<HorizontalScrollView
<LinearLayout
<LinearLayout (This layout is so the album cover is displayed correctly)
<ImageView
</HorizontalScrollView> <!-- end the album HSV here --!>
<ScrollView
<LinearLayout
<TextView (Songs)
<TextView
<TextView
<TextView
</ScrollView>
Whats happening is you are wrapping the vertical ScrollView in your HorizantleScrollView for no reason. Now if you would like some level of left/right tug that would cause the next whole page to show up - I would switch to the ViewPager. (If you aren't sure what I mean here, look at Google Play. They have vertical ListViews and you can pull left and right for new pages...

Categories

Resources