I have an activity page that I have placed images, buttons, etc. on. I am realizing it's going to be too large to fit on a mobile screen, so I want to make the page scrollable.
My current xml file for the activity looks like the following:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".bakers">
...
</androidx.constraintlayout.widget.ConstraintLayout>
I searched online and have tried multiple solutions, but the problem with every solution is that, though sometimes I'm able to scroll on the page, the format/layout of the activity gets all messed up.
For example, if I do this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
...
the format is still messed up. I've also tried to use a Relative Layout setup, but that doesn't help either.
Any suggestions?
add scrollView to the .xml file and put the objects that you want to be scrollable.
try this guide: https://www.youtube.com/watch?v=69C1ljfDvl0&t=287s
The code is in the description if you dont want to watch the video. hope it will help you.
Related
I'm creating a simple app for personal use and I'm stuck because I need to add/remove a text from my scrollview. In the screenshot below the blue square is my scrollview and the mail button (placeholder) needs to open a popup where I can put 2 values in 2 different boxes, a string and a double.
Main_Activity
I know how to do almost everything but I don't know how to add a text every time I click on the mail button and it should look like this when I click on it
this is how it should be when is done
The left button of a car block is the "delete from scrollview" button that removes it from the scrollview and preferences and the right button that does like the 2nd image but where I can edit it.
My questions are:
How can I add a "block" of items in a scroll view? Per block I mean: Edit and delete button and the text like in the example.
Suggestions on what to use for the popup that adds 2 input fields?
In my opinion, I suggest to use recyclerView instead because of performance issues.
link
But, if you need to do the way using ScrollView just follow this.
In your xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/holo_blue_dark"
android:fillViewport="true"
android:padding="16dp">
<LinearLayout
android:background="#android:color/holo_red_light"
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
And add item into linear layout when handle click event.
val linear = view.findViewById<LinearLayout>(R.id.linearLayout)
val item =
LayoutInflater.from(requireContext()).inflate(R.layout.item_list_row, linear, false)
linear.addView(item)
I'm currently working on a Grade Manager for school written in Java for Android 6. I just started with Android so I'm no expert.
The Problem:
If I call the method notifyItemRemoved() on my RecycleView Adapter and the last CardView moves from the left bottom place to the upper right place, the View is resized and the animation is cut of.
Now I don't know why that view is resized because RecycleView's layout_height attribute is match_parent.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".SemesterActivity"
tools:showIn="#layout/activity_semester">
<android.support.v7.widget.RecyclerView
android:id="#+id/subject_list_view"
android:padding="20dp"
android:layout_below="#+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
</android.support.v4.widget.NestedScrollView>
I took a GridLayoutManager as LayoutManager for the RecycleView.
subjectListView.setLayoutManager(new GridLayoutManager(ActivityContext, 2));
How i update the RecycleView:
SubjectAdapterObj.notifyItemRemoved(viewHolder.getAdapterPosition());
The animation is the default animation.
Could the GridLayoutManager be the problem?
Video Example:
Sorry. English is not my native language.
So I finally found out what the problem was.
It actually was the NestedScrollView which resizes it's children.
So what you need to do is to simply add android:fillViewport="true" to your NestedScrollView.
Thats it. I hope it helps someone although it's not a really difficult bug. I just searched at the wrong places.
I want realize a particular app in which you can scroll an image (background) infinitely. How can i do?
For example, my .xml is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/wallpaper" >
Thank you.
For infinite scroll you can use CWAC MergeAdapter. Here you can read what it is and how it works: https://github.com/commonsguy/cwac-merge
This is my first attempt to write a "simple" android app. Sadly I recognized that my app that displays content from a csv file looks different on my galaxy sIII mini comparing to the AVD. The weird thing is that in the AVD all - for example 400 - entries in the csv file could be displayed properly. In contrast to my smartphone where the TableLayout composed of TableRows including TextViews don't show any values (no error occurs). If I change the number of lines in the csv file (from 400 to 80 for instance) the TextViews are being displayed on the smartphone screen. A strange thing is also that the content which seems not being displayed is there but not visible. If I click on the screen of my smartphone the click event is being called and I can see in the log output that the values are being printed out to the console.
The TableRows and TextViews are being added at runtime. The number of TextViews depends on the number of columns and the number of TableRows depends on the entries in the csv file. The "firstAddressRow" is filled with the column headings.
Here is my layout definition of the activity object being used:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background_panel">
<Button android:layout_width="fill_parent" android:layout_height="40dp" android:onClick="updateCanvas" android:text="Update"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="vertical">
<LinearLayout android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<HorizontalScrollView android:id="#+id/horizontalScrollView"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<TableLayout
android:id="#+id/addressTable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:orientation="horizontal"
android:alpha="0.9">
<TableRow
android:id="#+id/firstAddressRow">
</TableRow>
</TableLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
</LinearLayout>
Does anyone know where my mistake is? I thought that maybe I have to refresh or update the layouts and views again but no "invalidate" or update function was successful.
The button I inserted at the top was just an experiment. The updateCanvas method only deletes some TableRows and the weird thing is that if enough TableRows have been deleted I see the TextViews again. And I know I already mentioned it in the introduction but with the AVD it is working fine. I would really really appreciate it if somebody could help me out... It's so frustrating...
If you need more information or more code than please let me know.
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. ;-)