Size of a Graph on android - android

i'm very new to Android and AChartengine and i'm working in my project.
Assume i have a Layout like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/displayECG"
android:layout_width="fill_parent"
android:layout_height="100px"
android:orientation="horizontal" >
</LinearLayout>
And in MainActivity.java i code like:
view = ChartFactory.getLineChartView(this, dataSet, renderer);
LinearLayout layout = (LinearLayout) findViewById(R.id.displayECG);
layout.addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
But when i run my App and i got a graph, it very smaller than layout space. I want a graph, it fits with my layout, so how can i do that?
Thanks,

Related

Advertisement to appear above and below the main layout in ListView

I want to display a picture advertisement at the bottom of the display area. I've tried using bottom but it didn't work. Can you help me?
MainActivity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"
></include>
<LinearLayout
android:id="#+id/adLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"></LinearLayout>
<ListView
android:id="#+id/ilcelerListview"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>
</LinearLayout>
Picture link : For Example
I can give your two tip to do that.
You can use RelativeLayout instead of LinearLayout at MainActivity.
For that, you can easy to add a view which you want to add to bottom.
Or
ViewGroup rootView = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);
LayoutParams params = new LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
//you can use params to set in the bottom or other positions
//view is yours
rootView.addView(view, params);

How can I resize two fragments in the screen by focus?

I have three fragments, the first two filling 80% of the screen and the last one with the rest (this one is never going to change in size). I want to, after input from the user (focus) in a fragment, resize the fragment so it fills 70% of the screen (leaving 10% to the other one). Like this:
It is possible to dinamically change the weight of a fragment?
Or there is a better way to achieve this?
This is the code I have right now in the XML:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1.0">
<FrameLayout android:id="#+id/containerParent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".8">
<LinearLayout
android:id="#+id/MainLinear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1.0">
<FrameLayout android:id="#+id/fragment1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight=".5"/>
<FrameLayout android:id="#+id/fragment2"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight=".5"/>
</LinearLayout>
</FrameLayout>
<FrameLayout android:id="#+id/fragment3"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight=".2"/>
</LinearLayout>
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
It should be something like :
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT, WEIGTH_HERE);
Assuming that WEIGHT_HERE is a float (cast may be needed).
(I don't know if it's a good way to do it but it should do what you want to)
And if you want to use this with a button or something just do the same without
the WEIGHT params and add :
Button b = new Button(this);
param.weight= (float) 0.5 // 0.5f
b.setLayoutParams(param);
But this method will create a new Layout Paramater, so if you want to kept everything just do the same but do not create a new layout, edit the existing one by getting it :
LinearLayout.LayoutParams mLay =
(LinearLayout.LayoutParams)myLay.getLayoutParams();
mLay.weight = (float) WEIGTH // WEIGHTf

setting the view dynamically from the java file

I am trying to make the java file set the view for the activity dinamically by using a specific number of linearlayouts and setting the source images
so how can I use java code to create a specific number of Image Views
<?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="match_parent"
android:orientation="vertical" >
<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">
<ImageView
android:id="#+id/menuline"
android:layout_width="match_parent"
android:layout_height="85dp" >
</ImageView>
</LinearLayout>
</ScrollView>
To create an ImageView (assuming this in an Activity):
ImageView imageView = new ImageView(this);
imageView.set(...) //configure your imageView according your needs
...
imageView.setLayoutParam(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,85); //set width and height
To add your imageView to the linearLayout :
linearLayout.addView(imageView);

handling various frame layouts in android

i'm new to game development and am trying create a Contra or the old tmnt game (but a simple one) like game for android. for the game i decided to divide my main screen in three parts - upper for stats,mid for the game and lower for controls.
my main.xml is
<?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="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/upper_bar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
</FrameLayout>
<FrameLayout
android:id="#+id/fl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5" >
</FrameLayout>
<FrameLayout
android:id="#+id/low_bar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.85" >
</FrameLayout>
</LinearLayout>
so i have created the gameview and gameloopthread classes for the mid surface(which is pretty standard). my problem is that how do i draw in the upper and lower frame layouts?
should i make new classes for view and thread for each layout , should i do all this in the gameview class itself or is there any better way to implement this?
You can reference to that layouts doing this:
FrameLayout upper = (FrameLayout)findViewById(R.id.upper_bar);
upper.addView( yourCustomView );
FrameLayout lower = (FrameLayout)findViewById(R.id.low_bar);
lower.addView( yourCustomView );

Change activity background from code

I have an activity with a background:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px"
android:background="#drawable/background_fingerboard" />
How can I change background image from code? I actually use mono, but Java samples will also be helpful.
first add LinearLayout id as in your layout xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/linearLayoutid"
android:minWidth="25px"
android:minHeight="25px"
android:background="#drawable/background_fingerboard"
and in code part set background as::
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayoutid);
linearLayout.setBackgroundResource(R.drawable.background_fingerboard);
In java we do like this
Give id to LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id=#+id/parentLayout
Then in code
LinearLayout layout=(LinearLayout)findViewById(R.id.parentLayout);
layout.setBackgroundColor(Color.BLUE); Or
layout.setBackgroundDrawable(d); Or
layout.setBackgroundResource(resid);
LinearLayout vi = (LinearLayout ) findViewById(<id>)
vi.setBackgroundResource(R.drawable.<id2>);
you need to provide the id to your LinearLayout in XML as well....

Categories

Resources