Im trying to create a nice plot with Xamarin and Microcharts. Unfortunately, Microcharts doesn't seem to be maintained any more and axes labels are not supported directly.
I'm wondering whether there is a way to add axes labels manually. My code for plotting the signal looks as follows:
private void PlotSignals() {
ChartView chartView = FindViewById<ChartView>(Resource.Id.chartView);
var chart = new LineChart();
chart.IsAnimated = false;
chart.LineMode = LineMode.Straight;
chart.PointMode = PointMode.None;
var chartEntries = //my chart entries
chart.Entries = chartEntries;
chartView.Chart = chart;
}
The corresponding .axml layout file looks as follows:
<?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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_myActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<microcharts.droid.ChartView
android:id="#+id/chartView"
android:layout_width="match_parent"
android:layout_height="160dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:id="#+id/StartButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_weight="0.5"
android:text="Start"
/>
<Button
android:id="#+id/StopButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Stop"
/>
</LinearLayout>
</RelativeLayout>
Related
I am trying to import google map in to my xamarin.android application. I set the key and written code as following `
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Maps);
SetUpMap();
FindViewElements();
}
private void SetUpMap()
{
if (mMap == null)
{
var _mapFragment = FragmentManager.FindFragmentByTag("maptag") as MapFragment;//null
var mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);//null
// var mapFragment = FragmentManager.FindFragmentById<MapFragment>(Resource.Id.map);//Here are also null
// var _mapFragment = SupportFragmentManager.FindFragmentById(Resource.Id.map) as SupportMapFragment; /null
}
}
protected override async void FindViewElements()
{
_mapsModel = new MapsModel
{
MapsFragment = FragmentManager.FindFragmentById<MapFragment>(Resource.Id.map),
MapTypeSpinner = FindViewById<Spinner>(Resource.Id.spinner),
Toolbar = FindViewById<Toolbar>(Resource.Id.mapToolbar),
};
SetSupportActionBar(_mapsModel.Toolbar);
SupportActionBar.Title = "Maps";
SupportActionBar.SetHomeButtonEnabled(true);
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
_mapsModel.MapsFragment.GetMapAsync(this);
_mapsModel.MapTypeSpinner.ItemSelected += MapTypeSpinner_ItemSelected;
}
I have axml as following
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="#+id/header">
<include
android:id="#+id/mapToolbar"
layout="#layout/toolbar" />
</RelativeLayout>
<Spinner
android:id="#+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/maptype_arrays" />
<fragment
android.id="#+id/map"
android:tag="maptag"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
</LinearLayout>
I tried every possible way which I found like replacing Fragment to suppportFragment but nothing got helped. Can any one please suggest me to achieve this.
Thanks in advance
I try your axml, and I get the result as your, so I suggest you can add fragment in FrameLayout, so you can get this fragment by Id. Like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="#+id/zoomInButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Zoom In" />
<Button
android:id="#+id/zoomOutButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Zoom Out" />
<Button
android:id="#+id/animateButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Animate to Location" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</FrameLayout>
var mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
var mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
You can also take a look the MSDN document about importing Google map in your project:
https://learn.microsoft.com/en-us/xamarin/android/platform/maps-and-location/maps/maps-api
I am new to xamarin. Is it possible to load a shared UI control in an xml file, if yes, how? I am open to better idea.
Below is a static loading via include, where parent.axml statically load child.xml.
<include
android:id="#+id/child"
layout="#layout/child"
android:layout_below="#id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
parent.axml
<?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">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<include
android:id="#+id/child"
layout="#layout/child"
android:layout_below="#id/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/parent_layout"
android:layout_below="#id/child">
<TextView
android:id="#+id/parent_text"
android:layout_margin="16dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click to go to the moon!"
android:textAppearance="?android:attr/textAppearanceSmall"
android:singleLine="true" />
</LinearLayout>
</LinearLayout>
Child.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/child_text"
android:layout_margin="16dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="You made it!"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
The idea is that it can achieve share of UI controls. In this case, parent.axml loads child.xml into its place holder based on condition.
You can use LayoutInflater to inflate layouts and auto-attach them to the parent (or not):
var linearLayout = LayoutInflater.Inflate(Resource.Layout.Child, parent, true);
var textView = linearLayout.FindViewById<TextView>(Resource.Id.child_text);
textView.Text = "Inflated and attached to Parent";
Also depending upon your use-case, using a self-contained Fragment and adding that to your "parent" might be better a better solution.
I have created a dialog fragment in Xamarin. My only issue is that this fragment shows a grey part on it. And i can't figure out what causes the grey part to appear. Do you guys perhaps know the possible cause ?
I'm using this code to display this dialog :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:focusableInTouchMode="true">
<View
android:id="#+id/makedialogfullscreenChooseSoundTrack"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_gravity="fill_horizontal"
/>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#e1effa" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Choose Sound Track"
android:textSize="20dp"
android:textColor="#673ab7"
android:padding="15dp"
android:layout_marginRight="25dp"
/>
<ImageView
android:id="#+id/imgCloseSoundDialog"
android:layout_width="33dp"
android:layout_height="33dp"
android:src="#drawable/close_icon"
android:layout_marginBottom="15.5dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_centerVertical="true" />
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<GridView
android:id="#+id/gvSoundFiles"
android:layout_width="fill_parent"
android:layout_height="400dp"
android:gravity="center"
android:verticalSpacing="5dp"
android:drawSelectorOnTop="true"
android:stretchMode="columnWidth" />
</LinearLayout>
</LinearLayout>
I solved the issue by adding this line in OnCreateView(..) method :
Dialog.Window.RequestFeature(WindowFeatures.NoTitle);
by default the DialogFragment comes with a theme with a title bar, to solve this put the code below in the constructor
SetStyle(DialogFragmentStyle.NoTitle, 0);
I try to use a RecyclerView in a SlideMenu.
I use this example for my SlideMenu : https://github.com/jamesmontemagno/PagerSlidingTabStrip-for-Xamarin.Android
And now, I add RecyclerView with SlideMenu. I need two menu : "menu" and "product", so I use two xml file for my fragment : menu.xml for "menu" and menu_recyclerView.xml for "product".
This is my code :
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true" >
<include
android:id="#+id/top_menu"
layout="#layout/top_menu"/>
<com.refractored.PagerSlidingTabStrip
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:pstsShouldExpand="true"
android:background="#color/Blue"
app:pstsDividerWidth="1dp"
app:pstsDividerPadding="12dp"
app:pstsDividerColor="#50FFFFFF"
android:textColor="#color/Green"
app:pstsTextColorSelected="#color/White"
app:pstsIndicatorColor="#color/Red"
app:pstsUnderlineColor="#color/White"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
menu_recyclerView.xml
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="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.support.v7.widget.CardView
android:id="#+id/menu_recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
</LinearLayout>
row_recyclerView is a pattern for my items
row_recyclerView.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"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:paddingRight="15dp"
android:paddingLeft="15dp"
android:orientation="vertical">
<refractored.controls.CircleImageView
android:id="#+id/imageView"
app:civ_border_width="2dp"
app:civ_border_color="#000000"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="88"
android:orientation="vertical"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:paddingTop="7dp"
android:paddingBottom="7dp">
<TextView
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtName"
android:textColor="#000"
android:gravity="center_vertical"
android:padding="2dp"
android:textSize="18sp" />
<TextView
android:text="Brand"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtBrand"
android:textColor="#000"
android:gravity="center_vertical"
android:padding="2dp"
android:textSize="14sp"
android:singleLine="true" />
<TextView
android:text="Description"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtDescription"
android:textColor="#000"
android:gravity="center_vertical"
android:padding="2dp"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
-
public class MainActivity : BaseActivity
{
protected override int LayoutResource
{
get
{
return Resource.Layout.Main;
}
}
private Android.Widget.Toolbar _topMenu;
private Adapter _adapter;
private ViewPager _pager;
private PagerSlidingTabStrip _tabs;
private RecyclerView _recyclerView;
private LayoutManager _layoutManager;
public string _tag = "MainActivity";
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
_recyclerView = FindViewById<RecyclerView>(Resource.Id.recyclerView);
_layoutManager = new LayoutManager(this, _recyclerView);
_layoutManager.addItem("one", "two", "three");
_layoutManager.addItem("one", "two", "three");
_layoutManager.createLayoutManager();
_adapter = new Adapter(SupportFragmentManager);
_pager = FindViewById<ViewPager>(Resource.Id.pager);
_tabs = FindViewById<PagerSlidingTabStrip>(Resource.Id.tabs);
_pager.Adapter = _adapter;
_tabs.SetViewPager(_pager);
_topMenu = FindViewById<Android.Widget.Toolbar>(Resource.Id.top_menu);
SetActionBar(_topMenu);
}
-
class LayoutManager
{
public RecyclerView _mRecyclerView;
public RecyclerView.LayoutManager _mLayoutManager;
public RecyclerView.Adapter _mAdapter;
public ItemList<Item> _mItems;
public Activity _main;
public LayoutManager(Activity main, RecyclerView recyclerView)
{
_main = main;
_mRecyclerView = recyclerView;
_mItems = new ItemList<Item>();
}
public void createLayoutManager()
{
_mLayoutManager = new LinearLayoutManager(_main);
_mRecyclerView.SetLayoutManager(_mLayoutManager);
_mAdapter = new RecyclerAdapter(_mItems, _mRecyclerView);
_mItems.Adapter = _mAdapter;
_mRecyclerView.SetAdapter(_mAdapter);
}
public void addItem(string name, string brand, string description)
{
_mItems.Add(new Item()
{
Img = Resource.Drawable.Icon,
Name = name,
Brand = brand,
Desciption = description
});
}
}
And in this line (in my LayoutManager.cs):
_mRecyclerView.SetLayoutManager(_mLayoutManager);
I have This error :
System.NullReferenceException: Object reference not set to an instance of an object.
I do not understand what is the value of the probleme ?
I forget any thing ?
I am completely lost ?
Please.. help !
Thanks you,
Romain
According to your code: public class MainActivity : BaseActivity and
protected override int LayoutResource
{
get
{
return Resource.Layout.Main;
}
}
I guess that your BaseActivity is the same as BaseActivity.cs of PagerSlidingTabStrip sample.
Then you actually here set your Main.xml as the content view of your MainActivity, and in this Main.xml, there is no RecyclerView with the id recyclerView, it is in your menu_recyclerView.xml. Although you can find the id recyclerView when you coding, but it is not present on the content view.
So in your MainActivity, when you try to find it using _recyclerView = FindViewById<RecyclerView>(Resource.Id.recyclerView);, this _recyclerView here should be null when you run your code. Then of course when you call _layoutManager = new LayoutManager(this, _recyclerView);, you pass a null to this LayoutManager. You can insert a break point on this line to check if it is a null:
_recyclerView = FindViewById<RecyclerView>(Resource.Id.recyclerView);
To solve your issue, I think you may need to redesign your layout or your frame.
Thanks for your answer !
Yes my BaseActivity il the same as BaseActivity.cs of PagerSlidingTabStrip sample.
I follow your advice, and yes I have a probleme with my architecture.
I learn how it works the RecyclerView, and I add this :
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true" >
<include
android:id="#+id/top_menu"
layout="#layout/top_menu"/>
<com.refractored.PagerSlidingTabStrip
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:pstsShouldExpand="true"
android:background="#color/Blue"
app:pstsDividerWidth="1dp"
app:pstsDividerPadding="12dp"
app:pstsDividerColor="#50FFFFFF"
android:textColor="#color/Green"
app:pstsTextColorSelected="#color/White"
app:pstsIndicatorColor="#color/Red"
app:pstsUnderlineColor="#color/White"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<include
layout="#layout/recyclerView" />
</LinearLayout>
menu_recyclerView.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"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:paddingRight="15dp"
android:paddingLeft="15dp"
android:orientation="vertical">
<refractored.controls.CircleImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:civ_border_width="2dp"
app:civ_border_color="#000000"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="88"
android:orientation="vertical"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:paddingTop="7dp"
android:paddingBottom="7dp">
<TextView
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtName"
android:textColor="#000"
android:gravity="center_vertical"
android:padding="2dp"
android:textSize="18sp" />
<TextView
android:text="Brand"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtBrand"
android:textColor="#000"
android:gravity="center_vertical"
android:padding="2dp"
android:textSize="14sp"
android:singleLine="true" />
<TextView
android:text="Description"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtDescription"
android:textColor="#000"
android:gravity="center_vertical"
android:padding="2dp"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
I add the new xml file : recyclerView.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
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.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v7.widget.CardView>
Now I call recyclerView.xml in my Main.xml. recyclerView.xml contain CardView, and he wrap RecyclerView.
I should put my RecyclerView in a only CardView or I should to wrap my menu_recyclerView.xml with cardView ?
I want to create a menu like this :
I have a result, but now I think I have a probleme with my menu_recyclerView.xml because I don't have a list, juste "name, brand, description". screenshot :
I search for this, and is a another subject...
I think the good keyword for this probleme is : RecyclerView, CardView
for finish this is my other sources :
https://www.binpress.com/tutorial/android-l-recyclerview-and-cardview-tutorial/156
How to add listView inside cardView android?
How to implement RecyclerView with CardView rows in a Fragment with TabLayout
Thanks a lot,
I am stuck at gridview.
I want an imageview below Gridview to handle click event of that.
Basically what i need is when click on this imageview button(here imageView_uparrow) it will slide up the layout which contains this gridview,
but when I add imageview(imageView_uparrow) below gridview(imageView_uparrow) in xml and run the project; gridview repeats that imageview on every grid icon.
I want that imageview to be appeared once at the bottom. Here is my XML.
<RelativeLayout 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:layout_gravity="top" >
<GridView
android:id="#+id/inside_gridView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginTop="58dp"
android:alpha="0.1"
android:background="#696969"
android:columnWidth="10dp"
android:gravity="center"
android:numColumns="3"
android:padding="4dp"
android:scrollbars="vertical"
android:stretchMode="columnWidth" >
</GridView>
<ImageView
android:id="#+id/image_insidegrid"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="5dp"
android:contentDescription="#string/hello_world" />
<ImageView
android:id="#+id/imageView_uparrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="22dp"
android:layout_marginRight="20dp"
android:contentDescription="#string/hello_world"
android:src="#drawable/drop_down_top_arrow" />
</RelativeLayout>
Last imageview i.e imageView_uparrow keep on repeating with the gridview items.
Please help me with this.. Thanks in advance.!
Hey I got the solution..
i kept my imageView_uparrow in separate xml and image which i used to set as an icon of my grid separate xml.And just inflated and added that to the Layout.
My modified Grid Xml is here
<RelativeLayout 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:layout_gravity="top"
android:id="#+id/parentRel"
>
<GridView
android:id="#+id/inside_gridView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginTop="42dp"
android:background="#drawable/transperant_background"
android:gravity="center"
android:numColumns="3"
android:padding="0dp"
android:scrollbars="vertical"
>
</GridView>
</RelativeLayout>
This is my xml file for ImageView(imageView_uparrow).
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_up_arrow_for_gridView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageview_up_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:contentDescription="#string/app_name"
/>
</RelativeLayout>
Code i use to inflate
Context context;
RelativeLayout rel;
ImageView upArrowImage;
LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
context=this;
View grid2;
rel=(RelativeLayout)findViewById(R.id.parentRel);
animate = AnimationUtils.loadAnimation(this, R.anim.slide_up);
animate.setAnimationListener(this);
LayoutParams lp = new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(14, 400, 0, 20);
grid2=new View(context);
grid2=inflator.inflate(R.layout.gridview_up_arrow_button,null);
upArrowImage=(ImageView)grid2.findViewById(R.id.imageview_up_arrow);
((ViewGroup)upArrowImage.getParent()).removeView(upArrowImage);
rel.addView(upArrowImage);
upArrowImage.setImageResource(R.drawable.drop_down_arrow4);
upArrowImage.setLayoutParams(lp);