Android SDK HorizontalScrollView - java

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...

Related

Element of listview out of bounds(visually) because of round edges

I am making an android app using Java in android studio. I have defined drawable background for listview with round edges. But last shown row is visually out of listview container. It is not just the line separating it from next record but also "-" symbol can be halfway out of the container. The app looks like this
is there a way to keep content inside the bounds?
It's happening bcz your background is different to listview and list view is always a square layout.
So basically, use cardview and set app:cardCornerRadius="" to cardview and list view set inside of cardview.
like this.
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="10dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="YOUR_BACKGROUND"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
OR
The other option is to use a round corner layout.
Git link
and set list view inside of any RoundCornerLayout.

How to make a layout in android that sticks to the bottom of the screen until the scrollview is scrolled to a certain position it gets scroll too?

I want to make a android activity screen where a layout is sticked to bottom until scrollview get scroll to a certain position. like in this video samples links:
https://drive.google.com/open?id=0B14wNBitoI33LWtUNThqcXRIUWc
https://drive.google.com/open?id=0B14wNBitoI33QW1BOGR1di1TcGc
amarjain07's StickyScrollView maybe a solution you would want to look into. His methodology of assigning the "sticky" views as identified attributes in the layout xml is quite a nifty feature IMHO.
Use a RelativeLayout and put the Button-Container inside it.
Pass the container in your_scrollview_activity.xml the following attribute
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 1 (reft)" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 2 (right)"/>
</LinearLayout>
</RelativeLayout>
NOTE: You need to set a listener in your activity to get the ScrollViews current position / current height. With this current height you can calculate the "left space" to the bottom / end of the ScrollView. If your RelativeLayout reaches the bottom or if it's close to the bottom AND within the visible area, then call your animation.

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>

Customize position of handle of sliding drawer

I had researched many sources and tried but still cannot move the position of handle from center to right.
<SlidingDrawer
content >
<ImageButton <-- this is handle
android:id="#+id/handle" <-- i want to customize position
android:layout_width="50px"
android:layout_height="60px"
android:background="#drawable/icon_other" />
<LinearLayout
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_others"
android:orientation="vertical" >
//content
</LinearLayout>
</SlidingDrawer>
So what to do to customize the position?
Please give opinion. Thanks
Use a TableLayout. This works similar to a HTML Table concept, allowing you to define rows and columns where to place buttons and other components.
If you don't want to use a table layout for the entire screen, you should be able to nest the layout within another....

Categories

Resources