Android: Fixed size ScrollView not scrolling/scrolling weird - java

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.

Related

Scroll behavior of Flexible Space in Android

To prevent from re-posting all my code again, it can be found in this question.
What I'd like to do now, is to prevent the upper imageview from shrinking upon scrolling; instead, I'd like to make it 'static' so it won't scroll up and shrink when the lower view is scrolled over it.
I'll add some pictures to compensate for the loss of clarification.
This is how the screen looks at it's fullest size:
This is how it looks when it's shrinked:
This is what I want:
Edit:
Forgot to mention what I tried and didn't work. Tried playing with the collapseMode of the ImageView which appears not related.
Also tried playing with the scrollFlags attribute of the CollapsingToolbarLayout, removing flags and adding enterAlways, but none worked. I have no clue on how to achieve this effect.
This simplest way would be to set the parallax multiplier to 1:
<ImageView
android:id="#+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="1" />

Using weightSum with ScrollView

I am new to Android.
I am stuck off in understanding the concept of using weight sum with weighted LinearLayouts. Have skimmed through a number of related questions on StackOverflow but still haven't found the solution.
Scenario
I have an activity layout page with number of components . The components are oriented vertically in the linear layout according to their layout_weights.
Code
<ScrollView fillViewPort="true" scrollBars="true">
<LinearLayout android:weightSum="150">
<!-- Various components present here each assigned layout_weight attribute
Total sum being 150 itself -->
</LinearLayout>
</ScrollView>
Question
My question is that how can I use scroll View and weightSum together such that a total of weightSum=100 displays on one page and for the rest 50 user needs to scroll down.
This is the one idea how it could possible
<LinearLayout weightsum="150" android:orientation="vertical">
<LinearLayout layout_weight="100">
//your LinearLayout
</LinearLayout>
<ScrollView Layout_weight="50">
//your scrollview layout
</ScrollView>
</LinearLayout>
Documentation says that the mission of weightSum is managing spaces below/under all the items of LinearLayout. Moreover, the weight does not purpose for specifying exact size of layout (but only for relative size), so nor for the paging. If you want to scroll Views page-by-page, you can use ViewPager.

android:gravity fails on API 18+

I have some TextViews on my app, I don't know why but the android:gravity attribute is not centering the text content where it should be on devices running the API 18+ (4.3+).
There is the code I use on my custom TextView, this is a child of RelativeLayout:
<com.package.custom.CustomTextFont
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/seekbar"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/seekbar"
android:layout_marginLeft="#dimen/margin_tiny_double"
android:layout_toLeftOf="#+id/seekbar"
android:gravity="center_vertical|left"
android:paddingRight="#dimen/margin_tiny"
android:text="#string/text1"
android:textColor="#color/black"
android:textSize="#dimen/size_text_normal" />
This code should take the edges of this TextView and align it to the top and bottom and put it to the Left of the SeekBar, this is working, but the TextView gets big, so with android:gravity I center the text to the center and left from it self. It works, but I don't know why, the text is not centered at center|left on devices running android 4.3 and 4.4. This issue can be reproduced on real devices and as well on the layout preview (Graphic layout) of Eclipse.
There is any changes made on API 18+ or on android:gravity that I'm missing?
PS: I'm targetting the API 19 on the project and on AndroidManifest.xml
PS2: My TextView is custom just to set an external font.tff
This is how it looks like on API 17-
This is how it looks like on API 18+
Thanks in advance!
= UPTADATE =
On my Manifest, I changed the android:targetSdkVersion to 17 instead of 19 and the problem disappeared, but this is a "trick", not a solution, what can I do since it could be an issue from the API ? And yes, I have the latest version of the API 18 and 19 (today, 01/30/2014).
This appears to be a known issue in API 18+:
https://code.google.com/p/android/issues/detail?id=59368
https://code.google.com/p/android/issues/detail?id=59700
The problem seems to occur when a TextView is part of a scrollable container (e.g. ListView), making the view ignore the vertical gravity for some reason (some sources suggest this has to do with the TextView being the child of a RelativeLayout, though it's been my experience that this can happen even when no such layout is involved).
A possible workaround (albeit not a particularly elegant one), would be to wrap the TextView in a LinearLayout. You can then use "layout_gravity" on the TextView to center it inside the LinearLayout, instead of relying on "gravity" (just make sure to wrap_content so the text itself is properly centered).
E.g., in your example:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignBottom="#+id/seekbar"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/seekbar"
android:layout_toLeftOf="#+id/seekbar"
android:layout_marginLeft="#dimen/margin_tiny_double" >
<com.package.custom.CustomTextFont
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="left"
android:paddingRight="#dimen/margin_tiny"
android:text="#string/text1"
android:textColor="#color/black"
android:textSize="#dimen/size_text_normal" />
</LinearLayout>
This method does have the disadvantage of adding an otherwise-unnecessary level to your view hierarchy, but it currently seems to be the only way around this (other than reverting to an earlier API level).
Also see similar question at:
Android sdk 18 TextView gravity doesn't work vertically
Your textview height is "wrap_content", which means the height of the textview will be the same as the height of the text. If you change the background of the textview to black, it might be easier to see the bounds of the view. I'm guessing you'll find that the textview doesn't have as much height as you expect.
Try setting the height of the textview to match_parent. You can wrap the textview inside another view if needed and modify its height as appropriate.

How can I add an image immediately to the right of the text in a FrameLayout wrapper, which holds one of two dynamically sized TextViews?

I have a FrameLayout which is a wrapper for a TextView. The TextView can be either one of two TextView objects with dynamically modified text. I would like to add an image immediately to the right of the text contained in the FrameLayout. I have tried two things:
I set up the FrameLayout inside a RelativeLayout. I added an ImageView:
<RelativeLayout>
<!-- Two TextViews Here -->
<FrameLayout
android:id="#+id/my_frame_layout"
android:layout_width="match_parent"
...
/>
<ImageView
android:id="#+id/my_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/my_frame_layout"
/>
</RelativeLayout>
This worked the first time the layout was loaded. However, when the text contained in the FrameLayout changed, the image stayed at its originally calculated position, rather than recalculating to stay to the right of the TextView.
So I tried making it a drawable and setting it in code. I fetched the TextView held in the FrameLayout, and called:
setCompoundDrawablesWithIntrinsicBounds(0,0,myDrawable,0)
This worked well, except that the drawable is always to the furthest right point of the FrameLayout, despite the TextView being only half full. I want the image to be immediately to the right of the text.
Does anyone have any other suggestions I could try to make this happen?
I ended up wrapping the ImageView in an additional LinearLayout, like so:
<LinearLayout
android:id="#+id/my_image_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="my_frame_layout"
android:gravity="left|center_vertical"
>
<ImageView
android:id="#+id/my_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Unlike the ImageView alone, the LinearLayout is redrawn when the text changes size, so this worked for me.

Design problem with android

Little confused with the design in android..suppose i need to position two blocks
as in the figure..what shall i do?..if we use pixels the design looks different in different phones.
Design should be fixed in all phones..but how without using px we can design as above
Use two LinearLayout in your layout xml and set layout_marginLeft,layout_marginTop,layout_marginRight in dip according to the need.
See the following layout, its very similar to the one you want:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:text="Button01"
android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dip"
android:layout_marginLeft="30dip"
></Button>
<Button
android:text="Button02"
android:id="#+id/Button02"
android:layout_below="#id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="140dip"
android:layout_marginRight="30dip"
></Button>
</RelativeLayout>
Hope this will solve your issue.
You could generate the layout in Java by getting the screen size and placing two objects (defined in xml or java) into the parent layout, taking into account the ratios.
If dip is unable 2 solve ur problm , surely any of these approaches will work :
1) take a 9patch backgroud with proportionate padding . now put first textview with gravity left|top and second with grvity right|bottom . done
or
2)Take two child of a vertical linearlayot with layout_weight=1 , so will each will take 50% height now to put put textview center vertical . now lets try fix it horizontally.4 each text
take two child textview with layout_weight=1 ,put text center_horizontal .for upper text male second invisible n for lower make first one invisible ......

Categories

Resources