TimeChart scroll (navigate) to specific X value after app starts up - achartengine

I'm trying to solve problem:
TimeChartView should be scrolled (navigate) to specific X axis value after app startup.
I'm trying to use ChartView.scrollTo (X, 0) and mChartView.setX(X)
But it works not like it was to be expected.
It's looks like ChartView moved by itself in layout instead of scroll.
Where is my mistake? Any other more suitable solution for this case?
Here is my code:
1) layout
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:fillViewport="true"
android:background="#000000"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/chartx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFAA00" <---------- ORANGE PART OF SCREEN, u can see on screenshot
android:gravity="bottom"
android:orientation="horizontal"
android:scrollbars="horizontal" >
</LinearLayout>
</LinearLayout>
</ScrollView>
2) activity
lChart = (LinearLayout) mapV.findViewById(R.id.chartx);
if (mChartView != null) {
lChart.removeView(mChartView);
}
mChartView = ChartFactory.getTimeChartView(mapActivity, mDataset, mRenderer, "dd/MMM/yy");
mChartView.scrollTo(100, 0);
lChart.addView(mChartView, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mChartView.repaint();
3) Data
for (int i = 0; i < 90; i++) {
c.set(c.MILLISECOND, 0);
c.set(c.SECOND, 0);
c.set(c.MINUTE, 0);
c.set(c.HOUR, 0);
time_series.add(new Date(value + i*cTimeChart.DAY), 0);
}
Let's say we are adding 90 values but we want our scrollable ChartView will be opened (visible) on value 45.
That's what I want to get to.
Here my screenshot
https://dl.dropboxusercontent.com/u/42675740/Screenshot.png
background="#FFAA00" - Orange part of screen, looks like ChartView moved inside layout.
And what I'm expecting - dates should be scrolled instead of view moving.
BTW. I'm using achartengine-1.1.0

Related

center the text in position 0, code problem xamarin

I looked everywhere, but for the moment works.
here is my code:
<Spinner
android:id="#+id/departement"
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="#color/colorAccent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_vertical|center_horizontal"
/>
Spinner departement = (Spinner)sender;
((TextView)departement.GetChildAt(0)).SetForegroundGravity(GravityFlags.CenterHorizontal);
((TextView)departement.GetChildAt(0)).SetTextColor(Color.White);
the color works, but the center position does not. do you have an idea ?
You can use a new xml to define the content of that item in Spinner.
And cusotmize the style in that xml .
Item.xml
<?xml version="1.0" encoding="utf-8" ?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" //center
android:textColor="#android:color/holo_red_dark"/> //Textcolor
Set in Adapter
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this,Resource.Layout.Item,items);
departement.Adapter = adapter;

Attempt to invoke virtual method 'void android.view.View.resolveLayoutParams()' on a null object reference

I have a ScrollView added to a FrameLayout. In a button click I remove the ScrollView from the FrameLayout and add an element derived from ViewGroup. If the button is clicked again the ViewGroup is removed and the ScrollView is added back. While adding the ScrollView back to the FrameLayout after removing the ViewGroup I get the following exception from the AddView method of the FrameLayout. Actually it is thrown from the AddView() method of ViewGroup class, since FrameLayout is derived from ViewGroup.
Unhandled Exception:
Java.Lang.NullPointerException: Attempt to invoke virtual method 'void
android.view.View.resolveLayoutParams()' on a null object reference
occurred
I have already tried to toggle the visibility of both Views instead of adding one and removing the other. But after toggling visibility, the application crashes every time when the FrameLayout's OnLayout is called such as when the Android keyboard appears or if the device orientation changes.
I am sorry that I am not able to provide the code. Because my code is very complex and I could not reproduce this problem in a simple sample. I just posted this question as a last resort.
I know it is not possible to get solution if code is not included. But any input related to this problem will be helpful.
Since you cannot provide the code here, I can only write part of the code to show your requirements:
in xaml,i add a ScrolView (with its children) and a LinearLayout(which as your ViewGroup) into a FrameLayout:
<?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">
<FrameLayout
android:id="#+id/framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above = "#+id/click"
>
<ScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text ="text in scrollview"
/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text ="text iFn LinearLayout"
/>
</LinearLayout>
</FrameLayout>
<Button
android:id = "#+id/click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
in activity show and hide the Scrolview and LinearLayout by click Button:
private int num = 1;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
Button button = FindViewById<Button>(Resource.Id.click);
FrameLayout frameLayout = FindViewById<FrameLayout>(Resource.Id.framelayout);
ScrollView scrollView = FindViewById<ScrollView>(Resource.Id.scroll);
LinearLayout linearLayout = FindViewById<LinearLayout>(Resource.Id.linearlayout);
button.Click += delegate
{
if (num % 2 ==0)
{
scrollView.Visibility = Android.Views.ViewStates.Gone;
linearLayout.Visibility = Android.Views.ViewStates.Visible;
}
else
{
linearLayout.Visibility = Android.Views.ViewStates.Gone;
scrollView.Visibility = Android.Views.ViewStates.Visible;
}
num++;
};
}

Imageview Inside Cardview Has A Image Src Which Bounds Out Of Imageview

I have a CardView with rounded corners, inside the CardView a ImageView is present.The issue is when i add the source inside the image the image goes out of ImageView hiding the round corners.
I have tried the code given below on macBook pro which produced the following results :
`<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:elevation="10dp"
app:cardCornerRadius="10dp"
android:layout_margin="5dp"
app:cardPreventCornerOverlap="false" >
<ImageView
android:id="#+id/card_view_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/competition_background"
android:scaleType="fitXY"
/>
</android.support.v7.widget.CardView>`
Try setting a defined width and height for your imageview. If your image is very large it will expand beyond the cardview. You could also choose to reduce the size of the image, which will result in a smaller apk. This is something to keep in mind when developping an android application. Never add larger resources than needed to your project.
So you could try something like this:
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:elevation="10dp"
app:cardCornerRadius="10dp"
android:layout_margin="5dp"
app:cardPreventCornerOverlap="false" >
<ImageView
android:id="#+id/card_view_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/competition_background"
android:scaleType="fitXY"
/>
</android.support.v7.widget.CardView>`
Another option is to add match_parent to your imageview but add a margin so it not expanded to the corners of your cardview:
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:elevation="10dp"
app:cardCornerRadius="10dp"
android:layout_margin="5dp"
app:cardPreventCornerOverlap="false" >
<ImageView
android:id="#+id/card_view_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="12dp"
android:src="#drawable/competition_background"
android:scaleType="fitXY"
/>
</android.support.v7.widget.CardView>`

how to combine status bar and toolbar with gradient in xamarin android

I want to combine status bar and toolbar with gradient like this
I have tried to set status bar transparent and make the toolbar big and set the gradient .
But It also makes your UI goes under the Soft navigation keys.
And also soft keyboard is covering the EditTexts.
android:windowSoftInputMode="adjustPan" not working
if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
{
Window window = Window;
window.AddFlags(WindowManagerFlags.LayoutNoLimits);
window.AddFlags(WindowManagerFlags.TranslucentNavigation);
}
Is there any way only the status bar make transparent rather than transparent both status bar and navigation button on the bottom.
You could alse do like this,add the code into the OnCreate method :
protected override void OnCreate(Bundle savedInstanceState)
{
if (Build.VERSION.SdkInt >= Build.VERSION_CODES.Kitkat)
{
Window w = Window;
w.AddFlags(WindowManagerFlags.TranslucentStatus);
w.SetSoftInputMode(SoftInput.StateHidden|SoftInput.AdjustResize);
}
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_other);
}
then create the gradient.xml in Resources/drawable :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:angle="135"
android:startColor="#f56f2c"
android:endColor="#fa9f46"/>
</shape>
at last in the layout.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation = "vertical"
android:layout_height="match_parent"
android:fitsSystemWindows= "true"
android:background= "#drawable/gradient"
>
<!--use Toolbar-->
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="标题"
app:titleTextColor="#fff"
app:subtitle="副标题"
app:subtitleTextColor="#fff"/>
<!--if dont use Toolbar,RePresent Toolbar-->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="44dp">
<ImageView
android:layout_gravity="center_vertical"
android:src="#drawable/ic_arrow_back_white_24dp"
android:layout_marginLeft="10dp"
android:layout_width="35dp"
android:layout_height="35dp" />
<TextView
android:layout_gravity="center_vertical"
android:textSize="25sp"
android:gravity="center_horizontal"
android:textColor="#fff"
android:text="Test Title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="#+id/scrollView1"
android:background = "#fff" //set the background color of your content
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation ="vertical" >
<!--your content -->
...
</LinearLayout>
</ScrollView>
</LinearLayout>
Why don't you set the color of status bar same as the startColor of gradient and let the toolbar start from where it does.
Create a static method that sets the status bar colour something like below:
public static void SetStatusBarGradiant(Activity activity)
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
Window window = activity.Window;
Drawable background = ResourcesCompat.GetDrawable(activity.Resources, Resource.Drawable.abc_ab_share_pack_mtrl_alpha, null);
window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
window.SetStatusBarColor(Android.Graphics.Color.Transparent);
window.SetNavigationBarColor(Android.Graphics.Color.Transparent);
window.SetBackgroundDrawable(background);
}
}
Then add a gradient.xml in drawable something like below see to it you set the start color and end color as per your requirement:
gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="#FFFF0000"
android:endColor="#FF00FF00"
android:type="linear" />
</shape>
</item>
</selector>
Goodluck
Revert if you have queries

Android align button and text in a table layout

I am trying to create a table view with a text view and a button in android. Below is my sample code ( work in progress ). As I am very new to android please help me how to arrange the text view and the button as in the image. Now I am getting button and text view. But its weird.
My Code
TableLayout table = (TableLayout)findViewById(R.id.tableLayout_1);
for (int i = 0; i<30; i++)
{
TableRow row = new TableRow(this);
row.setBackgroundColor(Color.DKGRAY);
TextView tv = new TextView(this);
Button btn=new Button(this);
tv.setTextAppearance(getApplicationContext(), R.style.maxWid);
tv.setText("Sample Text Here");
row.addView(tv);
btn.setText("Approves");
row.addView(btn);
table.addView(row);
}
Style.xml
<style name="maxWid">
<item name="android:textStyle">bold|italic</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:layout_width">fill_parent</item>
</style>
main_layout.xml
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:layout_weight="1">
<TableLayout
android:id="#+id/tableLayout_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
</TableLayout>
</ScrollView>
Expected format
Fighting with this since 1 day.. Please help
Thanks in advance!
what you can do here is create a layout xml using RelativeLayout and then add that into your TableRow.

Resources