Android: Making content scrollable with keyboard without resizing background - android

I have a RelativeLayout and inside it I have a LottieAnimationView and another LinearLayout. The LottieAnimationView serves as my background image and inside the LinearLayout I have my content with EditText and Button. So my problem is now that the content shall be scrollable when the softkeyboard is out but the background image shall not be resized. I have tried several things but nothing really worked.
My XML looks like this:
<RelativeLayout>
<LottieAnimationView>
<ScrollView>
<LinearLayout>
<EditText>
<Button>
</LinearLayout>
</ScrollView>
</RelativeLayout>

My Solution:
I had to put the LottieAnimationView inside the LinearLayout and set android:adjustViewBounds="true" to the Lottie View.

You can also set match_parent to your ImageView or LottieAnimationView in the layout xml and then in the activity/fragment/view set it's height to the current:
val height = yourBackgroundImageView.height
if (height > 0) {
yourBackgroundImageView.setHeight(height)
}
Just make sure it's done after the view was attached to the screen (and measured).

Related

Showing full height layout above recyclerview inside scrollview

As the title says. I'm trying to display extremely complex layout with a full height of the viewport but I need it scrollable because under it there is a simple recyclerview with some items. I already thought about putting everything inside a multi type recyclerview adapter but the logic of the upper layout is so complex that I don't think it's possible.
I tried using NestedScrollView with fillViewport set to true but I'm stuck defining dimensions of this upper layout and recyclerview below it. Everything needs to be inside one layout because scrollview can't have more than one child, but when I put everything in a linearlayout and set the upper layout to match_parent it's showing fullscreen until data loads in the recyclerview below it. Then it's treating this upper layout as if it was wrap_content.
I'm out of ideas how can I do something like this. Preferably best would be to have some sort of ViewGroup which would support scrolling and resize the recyclerview below it as we scroll, but I'm not sure how to do it.
you need to set the layout to something like this:
<NestedScrollView - height:match_parent>
<LinearLayout - height:wrap_content>
<LinearLayout(topview) - height:wrap_content/>
<RecyclerView - height:wrap_content />
</LinearLayout>
</NestedScrollView>
And then you programmatically change the height of the "topview" to equal nestedscrollview.

How to set a TextView at the bottom of the screen

I have this layout:
It was a bit tricky to put ListView inside ScrollView, but it worked.
When the list is large and the scroll appears when scrolling .. everything up, including the form. That is ok!
Now I would like to put a TextView fixed at the bottom of the screen. As a total
Tried to wrap everything with a RelativeLayout put layout_weight = "1" in ScrollView. Worked. But when the keyboard appears, rises along the TextView and do not want it.
How do I set a TextView at the bottom of the screen, without moving when the keyboard appears?
Put everything in a relative layout. Add the TextView to the relative layout, set layout_alignParentBottom on TextView. Then on the ScrollView set layout_above referencing the TextView.
Follow the design hierarchy:
<LinearLayout.....>
<ScrollView>
<You Old Views/>
</ScrollView
<TextView> .. </TextView>
</LinearLayout>

How to set ImageView as background for any container?

I'm in need to set an ImageView as a background for a let's say LinearLayout. Is that possible to do so?
I wish you wrote more details about what you require. If this is only about setting an image background, you can use the android:background property of LinearLayout. However, to answer your question directly, a view can be placed behind another using FrameLayout:
<FrameLayout>
<ImageView/>
<LinearLayout>
...
...
</LinearLayout>
</FrameLayout>
Yes it should be possible. In the layout xml, try wrapping the ImageView inside the LinearLayout. Then in Activity OnCreate function set the xml as content layout.

How to add more Items in Scrollview in Android?

My android page has 10 EditText and 10 TextView. but there is no space in my screen in the Graphical Layout. i just added 5 only. im using Scroll layout. how to add additional 5 items in the screen without reducing the items height. Is there any coding here.?
<ScrollView>
<LinearLayout>
<TextView/>..
....
..
</LinearLayout>
</ScrollView>
You can add multiple items inside a LinearLayout. Since ScrollView is scrollable it won't affect the dimensions of the Views inside. You can add as many views as you need without worrying about screen size or View size..
You should add a LinearLayout as the only child inside your ScrollView. Then get a reference to that LinearLayout :
mLayout=(LinearLayout)findViewById(R.id.myLayout);
and then add Views dynamically from code using :
EditText et=new EditText(...);
//....
mLayout.addView(et);
A ScrollView can have only one direct child, so you need to put all the other Views in a Layout, such as LinearLayout and put that layout in ScrollView
Make your ScrollView's height as match_parent and the inner LinearLayout's height as wrap_content. The LinearLayout will stretch according to the number of children inside it and if the height exceeds the height of the ScrollView, the overflow can be seen by scrolling. If the ScrollView and inner Layout both have same height or if ScrollView have larger height than inner Layout, the scrolling won't happen for obvious reason.

How to overlay text on the android map view

I have an application to show the MapView having both height and width fill_parent. I need to overlay some text on the top part of the Map View. How to do this?. The background of text should be transparent. Also the text has the property of marquee. Is it possible to do this?
Use a RelativeLayout as the root container of you layout and add the MapView and a TextView to it (below the MapView in the layout xml file). Use the TextView to display the text which should be displayed above the map. Now you can use the attributes starting withlayout_ to place the TextView where you want it.
As far as I know, the marquee effect only works when the TextView is focused and its text value is too long to fit in the whole TextView.
The TextView's background should be transparent by default.
Create a RelativeLayout as the container of your Mapview and a TextView
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<MapView .../>
<TextView /> </RelativeLayout>
You can display the TextView where you want with the RelativeLayout child attributes, for example on the textView : layout_alignParentBottom="true"
Otherwise just use an itermized overlay to put the text in.

Categories

Resources