I've got a layout with some views, from which one is an EditText. The layout easily fits on one page, BUT, when the soft keyboard is out, the layout doesn't scroll.
Here's a recap of my layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background" >
<ScrollView
android:id="#+id/ScrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<CheckBox/>
<TextView/>
<LinearLayout>
<EditText>
<requestFocus />
</EditText>
</LinearLayout>
<TextView/>
<LinearLayout>
<Spinner/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<Button
android:layout_alignParentBottom="true" />
</RelativeLayout>
And in my manifest I have declared the attribute:
android:windowSoftInputMode="adjustResize|stateHidden"
Does anyone know why it doesn't work and how to make sure it does work?
I had the same problem and I checked my activity in the manifest, and the reason why it wasn't working is because I didn't use this property:
android:windowSoftInputMode="adjustResize"
Now it works great and no need to do additional anchors.
Okay, apparently the ScrollView's android:layout_height mustn't be set to wrap_content. I set it to match_parent and set the android:layout_above to the button on the bottom of the page.
Don't ask me why, but this fixed the issue.
In my case, nothing of the above worked.
I had item name="android:windowTranslucentStatus">true</item> in my theme. And it was fixed by setting android:fitsSystemWindows="true" in the parent layout where is my scrollview.
Add android:windowSoftInputMode="stateHidden|adjustResize" to your tag in AndroidManifest.xml file. This will cause the screen to be resized to the left over space after the soft keyboard is shown. So, you will be able to scroll easily.
In my case any of the solution above does not work until I REMOVE
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
in my activity, I use that code to get a full screen display. Maybe for certain cases, try to remove any setup of full screen to make any of the above solution works.
If your First Fragment Scroll perfectly and the second fragment did not scroll then you should use the second fragment replace and do below things
1.Add in ScrollView
android:fillViewport="true"
android:fitsSystemWindows="true"
2.Add in Manifest
android:windowSoftInputMode="adjustResize|stateVisible"
If you add fragment then my suggestion is you need to Replace the Fragment
In my case I had to Remove the following property from my style to make it work .
<item name="android:windowFullscreen">true</item>
My problem was with a HorizontalScrollView. In my case I had to set HorizontalScrollView to:
android:layout_width="match_parent"
android:layout_height="match_parent"
And remove:
android:layout_above="#+id/closeButton"
android:layout_below="#+id/logo"
In the AndroidManifest.xml the activity is set to:
android:windowSoftInputMode=""
I hope this helps anyone comming across this weird bug.
In my case, what solved this was setting a missing constraint in the Bottom. My ScrollView had top, right, and left constraints, but no bottom one. After restricting it from all sides, it started to overlap the above textview, which prompted me to try putting the height to 0dp, and that seemed to solve the problem.
Try to set ScrollView as your parent layout. It works like charm for me!
<activity
android:windowSoftInputMode="adjustResize"
>
try this In android manifest ..
Related
Okey, so hello everyone.
I am pretty new to app developing.
Introduction:
In my app I have activity with RelativeLayout. In this layout I have zoomable FrameLayout. In this layout I have to have only one layout. In my case It is another RelativeLayout. Finally in this layout I have number of ImageViews. Purpose of this activity is show layers of map (drawables) via switches.
Code here:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorDarkBlueGrey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.example.cotwcompanion.ZoomableView
android:id="#+id/zoomView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/mapLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/mapBCG"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:contentDescription="#string/map_name"/>
<!-- Here I generate other ImageViews with 'same' attributes -->
</RelativeLayout>
</com.example.cotwcompanion.ZoomableView>
<!-- Here are other layouts -->
</RelativeLayout>
Problem:
My problem is more or less visual. I would like to show these layers (1:1 ratio) as big as display allows (vertically). Therefor I need to overlap display's width.
What I need It to look like:
IMAGE
What I have tried:
I thought FrameLayout would do it. So I tried to set its width
and height programmatically, so It fits screen height and has
the same width, because of 1:1 ratio mentioned before. If I try to log these dimensions, it seems like all is set. Because
of match_parent attribute in ImageViews and their parent RelativeLayout, It should therefor do everything else and stretch these Views to fill FrameLayout. But everything just
only fits screen width.
Image of result here:
IMAGE
Code here:
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(height, height);
FrameLayout frame = findViewById(R.id.zoomView);
frame.setLayoutParams(lp);
I tried the same method with normal FrameLayout but got same
result.
I also tried to exchange FrameLayout with
HorizontalScrollView and custom zoomable ImageView. This worked more or less well, but problem was when I zoomed the map.
Horizontal scroll disrupt every movement with zoomed map. Therefor I
tried to create custom HorizontalScrollView with methods to
disable scroll. Even when I catched zoomed state from ImageView
and set scroll to notEnabled, It still did not work.
And there you go. Like I said zooming methods and everything other works. I just need to somehow have bigger View than display allows.
EDIT [21.11.2020]:
So as Daxi suggested I tried to change RelativeLayout in ZoomableLayout to ConstraintLayout. I also changed ZoomableLayout to extend from ConstraintLayout. That almost solved my problem. However I could not scroll to left and right. I could only zoom. So I took one of my last tried solution and wrapped ZoomableView with HorizontalScrollView. Everything seemed okey. However I now just cannot scroll to the very 'start' or 'end' of the ImageView. It seems like I can only scroll within the base width of HorizontalScrollView and not width of ImageView. So I now need to solve this problem.
Code here:
<RelativeLayout>
<HorizontalScrollView>
<ZoomableView extends ConstraintLayout>
<ConstraintLayout>
<ImageView/>
.
.
</ConstraintLayout>
</ZoomableView>
</HorizontalScrollView>
.
.
</RelativeLayout>
I am so sorry if this is somehow a duplicate of other problem already described on stackoverflow, but I searched for solution over two days now and still did not find any. Maybe I am bad finder. If this will be the case, feel free to tell me. I will delete it if needed.
If there will be some pretty fine answer and solution I would really appreciate It. Thank you.
Would you consider using ConstraintLayouts? If yes, you could use it like this
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/mapLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/mapBCG"
android:layout_width="0dp"
android:layout_height="match_parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="#string/map_name"/>
<!-- Here I generate other ImageViews with 'same' attributes -->
</androidx.constraintlayout.widget.ConstraintLayout>
However, I am not sure how exactly this will interact with your ZoomableView
OK, Im starting to get the hang of how XML operates with the Android interface, but I've ran into a problem...
I just have a HorizontalScrollView with a RelativeLayout inside to which I will place other views later. The HorizontalScrollView as you can see is sitting above a button, and below another button. I like where its placed, but I dont want it exactly right above and below the buttons. I would like some spacing (padding). Ive tried adding padding but it seems to have no effect...
Heres my attempted XML:
<HorizontalScrollView
android:id="#+id/scrollview_xyzInfo"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_above="#+id/button_refresh"
android:layout_alignParentRight="true"
android:layout_below="#+id/button_mySettings"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:background="#drawable/refresh_selector" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
</RelativeLayout>
</HorizontalScrollView>
Any help would be much appreciated :-)
Nevermind! Use margins when seperating two views like so:
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
Answer Found at:
Padding not working Android
Padding and margin works only with LinearLayout. Which layout are you using?
I'm stuck figuring how to do the following requirement.
I need to make a simple screen with two buttons, like this:
That part of the screen is already done.
The hardest thing for me is to make the behavior of the two buttons
when they are pressed. In that case, they must show an option menu
below like this:
Button 1 Pressed:
Button 2 Pressed:
I didn't start to program the menu yet,but in case it helps, this is
the layout for the screen (without the buttons).
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/grayBackgound"
tools:context=".MenuActivity" >
<include android:layout_width="match_parent" layout="#layout/header" />
<include android:layout_width="match_parent" layout="#layout/loggedin_subheader"/>
</LinearLayout>
The layout for the header:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/header"
android:contentDescription="#string/header"
/>
<ImageButton
android:id="#+id/btnClose"
android:src="#drawable/btn_close"
android:contentDescription="#+string/salir"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="260dp"
/>
</FrameLayout>
The layout for the sub-header is almost the same.
I just need help to make the options menu for every button.
Thanks in advance!
The menu that you want to implement is what is commonly called a QuickAction Dialog. There are several tutorials available for that.
To get you started, here is a few links:
http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/
https://github.com/ruqqq/WorldHeritageSite (This is not a tutorial per se, but has the complete implementation for the QuickAction Dialog)
https://code.google.com/p/simple-quickactions/ (You will need to make a few modifications in this)
The first link is the most promising in your case. If you scroll down that page to the Gallery3D-like QuickActions section, you will see it kind of resembles what you want the end result in your app to be. Naturally, goes without saying, you will still need to make modifications to the source available on the site.
Hope this helps. ;-)
My app requires the ability to add several views on one line in a user selected order.
I found this tutorial which seems to accomplish what I want with a bit of modification.
http://www.androidpeople.com/android-custom-listview-tutorial-example/
Having followed the tutorial and made the required changes, the code works except for one strange issue. The position increments but when it hits ~9 it returns to zero and then re-adds views that are already in the list and thus never reaches the >9 ones.
Also, if I scroll down to the bottom and then back up the very first entry has changed! It may change more but I haven't checked that.
Through some tests I have discovered that the textSize has some effect. If I set it small enough so that all 'rows' will show on screen at once then they appear fine.
This is my listview layout that gets inflated into the main layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="60dip"
style="#style/DefaultTheme">
<TextView
android:id="#+id/Line01"
android:layout_width="5dip"
android:layout_height="fill_parent"
android:background="#F00" />
<TextView
android:id="#+id/Line02"
android:layout_width="5dip"
android:layout_height="fill_parent"
android:background="#0F0" />
<TextView
android:id="#+id/Line03"
android:layout_width="5dip"
android:layout_height="fill_parent"
android:background="#00F"
android:layout_marginRight="5dip"/>
<LinearLayout
android:id="#+id/LinearLayout"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="2dip">
<TextView android:id="#+id/Name"
android:text="Name"
style="#style/Name" />
<TextView
android:id="#+id/Status"
android:text="Status"
style="#style/Status" />
</LinearLayout>
<ImageView
android:id="#+id/StatusImage"
style="#style/StatusImage" />
</LinearLayout>
I change background colours and text but that is all. Any ideas what is the problem?
Thanks!
That's because ListView recycles Views. It creates as many Views as required then the one which isn't available will be recycled as next.
So you have to set the colors/attributes in the getView or bindView methods of the adapter.
And btw. what you posted doesn't inflate the ListView, as there is no `' object in it. At best it could be a single ListView item, but not the listview itself ^^
I feel dumb for asking this now and not going back over the tutorial completely.
I was setting the values in my layout I place in the ListView on my main layout only when a new ViewHolder was created. Thus when I scrolled, the views were recycled, but never updated with the correct View settings.
All working fine now!
Cheers
I have a main menu screen with a simple ListView that contains "links" to further screens in my app (Browse, Bookmarks, Settings, About, etc.). Underneath the ListView there is a TextView (more accurately, a TextSwitcher that rotates TextViews) that changes every 10 seconds to display a new "tip".
In portrait mode, this works fine. There are my five list items in the ListView , and my tip label underneath. However, when I switch to landscape mode, the ListView is taller than the screen. The ListView scrolls normally, but I cannot scroll past the end of the ListView to see the TextView underneath.
I have tried every possible combination of Layouts, wrappers, ScrollViews, and layout_height parameters and I simply cannot get it to behave.
Here is the simplest code I can use to get the result pictured above:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:orientation="vertical"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/ListLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ListView android:id="#id/android:list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1">
</ListView>
</LinearLayout>
<LinearLayout android:id="#+id/TipLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_below="#+id/ListLayout">
<TextSwitcher android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/TipSwitcher">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="7pt"
android:id="#+id/Tip1TextView" android:text="Tip: Hello, Android!"></TextView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tip: This is the second TextView in the TipSwitcher!"
android:id="#+id/Tip2TextView" android:textSize="7pt"></TextView>
</TextSwitcher>
</LinearLayout>
</RelativeLayout>
Like I've said, I've already tried so many different combinations that I can't list them, and for the most part I was randomly inserting XML in an attempt to get something to work the way I wanted. So I'd greatly appreciate suggestions as to how I would go about doing this the right way.
Thanks.
EDIT: Something I forgot to mention, this may or may not be relevant. My MainMenuActivity is extending ListActivity. According to the docs, "ListActivity has a default layout that consists of a single, full-screen list in the center of the screen." But, "If you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate()." So I don't think the ListActivity is interfering.
Put the TextSwitcher in the ListView itself. You can use addFooterView() for this.