How to put chart in ScrollViewer? - java

Consider a LinearLayout with some UI items and a TChart. If I put this layout inside a ScrollViewer I would expect scrolling behavior. However, it seems that the chart auto-sizes itself to fit in the available space.
How can I make my layout scrollable when adding a chart to it?

You should have you root tag as scrollview like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView>
<LinearLayout
android:orientation="vertical">
here will come your all UI items
</LinearLayout>
TChart
</ScrollView>
or
<?xml version="1.0" encoding="utf-8"?>
<ScrollView>
<LinearLayout
android:orientation="vertical">
here will come your all UI items
TChart
</LinearLayout>
</ScrollView>
You can also download and embbeded chart widget which is available as an external widget. and is not available as an inbuilt widget in android project.

Related

Where in android studio can I change the appbar text?

I'd like to change and align the text, and possibly add features on appbar in the screen above.
However, it'd be best if I could find and modify the text and align it IF I don't intend to add features.
But then I wasn't able to find where in android studio I could change the text.
I thought I could find one in the main activity xml file but I couldn't. I looked up at themes.xml and AndroidManifest.xml but couldn't find a clue.
Here is first 13 lines of my main activity xml file just in case.
<?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=".MainActivity">
<SurfaceView
android:id="#+id/surface_view"
android:layout_width="match_parent"
android:layout_height="480dp"
app:layout_constraintTop_toTopOf="parent"/>
So, to cut it short, where in android studio can I change the text in toolbar? or appbar? above in the screen without having to create toolbar.xml? (+ align the text in the center and change text color)
Apparantly you don't have toolbar implemented in your xml layout
In Your style file make sure you set it to noActionBar
<style name="Theme.ChatApp" parent="Theme.AppCompat.Light.NoActionBar">
Then you have to add your own toolbar
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/toolbar"
android:background="#color/white"
app:navigationIcon="#drawable/ic_baseline_dashboard_24"
app:title="here you can put your title"/>
In your activity reference your toolbar in your onCreate
setSupportActionBar(findViewById(R.id.toolbar)
PS : If you are using MaterialToolbar please consider add this material library
implementation 'com.google.android.material:material:1.1.0'

Android fragment preloading data

Hello I'm trying to make an application that has multiple bottomnaviagtion tabs.
Currently it works because fragment data (for example, images) are static. However, if I want to make them dynamic, I'll have to create a preloader.
So I want to display a loading layout (for example R.layout.loading) UNTIL (async) function has completed and obtained data from server. Then I want to replace the layout in the fragment with a new layout (R.layout.datafragment)
Fragment onCreateView:
return inflater.inflate(R.layout.loading, container, false);
In summary it should work exactly like youtube bottom tabs.
You should create in your activity layout a placeholder for those dynamic fragments and a loader which is by default gone, but when you start loading data from the server you should make it visible (loader). Then, when you load necessary data, just start fragment transition and place whatever fragment you have loaded.
Your parent activity's layout should be like this:
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Navigation View and Fragment Container-->
</RelativeLayout>
<RelativeLayout
android:id="#+id/progress_layout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
</RelativeLayout>
Then you simply show/hide progressLayout based on your requirement. Thanks

Create facebook like menu

I want to open a menu of options similar to that of Facebook. I did a search but I did not find anything ...
You will probably be needing to use Bottom Sheets for that :
I - Make a bottomsheet.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="300dp"
android:orientation="vertical"
android:padding="16dp"
app:layout_behavior="#string/bottom_sheet_behavior">
<!-- add your content here -->
</LinearLayout>
II- now in your main activity implement it in a way it is a direct child of a CoordinatorLayout
<include layout="#layout/bottomsheet" />
III- For the JAVA code use the following:
inearLayout bottomSheetViewgroup = (LinearLayout) findViewById(R.id.bottom_sheet);
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetViewgroup);
To control your bottom sheet (hiding, expanding, dragging, collapsing):
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
PS- you can handle this by :
STATE_EXPANDED: To completely expand the bottom sheet.
STATE_HIDE: To completely hide the bottom sheet.
STATE_COLLAPSED: To set the bottom sheet height with the value set on the peekHeight attribute.

Android App Background Colour Not Setting

I've recently started working on an Android app. I'm not a programming noob, I have been programming in Java since 2009, but this is my first Android app. I have tried following some tutorials on how to set the background colour but it simply isn't working for me. I can't work out what I'm doing wrong.
In my layout directory I have files called: main.xml and view_fact.xml. They both use the linear layout and my LinearLayout Tag is as follows:
<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_grey"
>
And in my "values" directory I the contents of "strings.xml" is:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Facts</string>
<color name="background_grey">#E8E8E8</color>
</resources>
But the background colour is not changing from the default black.
I've also tried adding: "android:theme="#android:style/Theme.Light"" in my AndroidManifest.xml file.
None of this is working, any suggestions?
Thank you.
On my view_fact.xml page it looks like this:
<?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_grey"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Fact:"
android:padding="10dp"
android:textColor="#080808"
/>
<TextView
android:id="#+id/factData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text=""
/>
<Button
android:id="#+id/anotherFactButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Another Fact"/>
</LinearLayout>
What's interesting is that the text in "factData" is grey, while the text: "Fact:" in the Text View above is white, and I've tried to change it's colour to red and it doesn't work. It stays white.
Any suggestions? I still haven't managed to get this working; thank you.
If you want to use #color/color_name you have to create a Color.xml file and then it will be accessible in the manner you tried to use it.
Forgive the somewhat obvious questions, but: are you calling setContentView(R.layout.main) in your Activity onCreate? Is there something else in the layout that is filling the LinearLayout and covering the background grey?
Looking at the pastie you linked in the comment I think you need to remove the <?xml version="1.0" encoding="utf-8"?> line at the start. Eclipse won't build a freshly created app with that xml root in a layout..
Although that's strange as the first two examples I've found on the Android Developer site (for example) include it
I'd be interested to see what happens if you remove that line...
In Eclipse if I use
<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="#E8E8E8"
>
then the background colour changes.
If I change that to
<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="#string/background_grey"
>
by adding <string name="background_grey">#E8E8E8</string> to /res/values/strings.xml the background changes.
This also works if I declare it as android:background="#color/background_grey" in the layout and <color name="background_grey">#E8E8E8</color> in strings.xml
and if I setup res/values/colors.xml <= I've used colors.xml (while you've used color.xml) however http://developer.android.com/guide/topics/resources/more-resources.html tells us the filename is arbitrary as you can see by the declaration working in the strings.xml file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background_grey">#E8E8E8</color>
</resources>
and declare the layout as
<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_grey"
>
then the background also changes...
If it doesn't behave the same for you then there's something funky going on or you're using a different layout than the simple example above and, well, there's something funky going on in that layout.
Okay, I've tried lots of different methods of trying to set the background colour and none of them are working. And I'm now having problems with text not updating. So I'm going to try remaking it. Using eclipse and ill make a new question if I'm still having issues. Thanks for the suggestions.

android:animateLayoutChanges won't work in parent layout

Suppose I have a layout file structured like this:
<LinearLayout android:id="#+id/main" android:orientation="vertical" android:animateLayoutChanges="true">
<EditText>
<TextView android:id="#+id/header1">
<LinearLayout android:id="#+id/insertionPoint" android:orientation="vertical" android:animateLayoutChanges="true">
</LinearLayout>
<TextView android:id="#+id/header2">
</LinearLayout>
I want to dynamically add text fields to the Layout insertionPoint and I would like to see an animation of the elements below it (in this case, header2) sliding down.
Using android:animateLayoutChanges only animates the elements in the layout insertionPoint, so there is no animation for header2. What should I do?
Just to be more clear: what I would like to do here is something like the animations that we can see in the People app in ICS when we add more fields, like telephone numbers, to a contact.
Thank you!
API 16 added the LayoutTransition.CHANGING animation type, however it is disabled by default.
To enable:
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.main);
linearLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
Nice DevBytes video: https://www.youtube.com/watch?v=55wLsaWpQ4g

Categories

Resources