Avoid repetition of view in android gridview - android-gridview

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);

Related

Adding axes labels to a Microcharts plot

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>

Dynamically load xml control and share UI control

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.

Xamarin - How can i remove extra space at the top of dialogfragment

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);

ImageButton doesn't shows the image

I have a problem running with the ImageButton. It does not show the image of the drawable folder, it shows a small gray rectangle.
Demomento I put only the code of the layout of the activity because by clicking on the rectangle that comes out if it does the action.
<?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"
tools:context="mdl.acp.Menu">
<Spinner
android:id="#+id/numeroGru"
android:layout_width="240dp"
android:layout_height="25dp"
android:layout_alignStart="#+id/textView6"
android:layout_below="#+id/textView6"
android:layout_marginLeft="35dp"
android:layout_marginTop="25dp"
tools:layout_editor_absoluteX="82dp"
tools:layout_editor_absoluteY="161dp" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/textView6"
android:layout_below="#+id/numeroGru"
android:layout_marginTop="46dp"
android:text="#string/seleccionaDtAct"
android:textColor="#color/colorPrimary"
android:textSize="18sp"
android:textStyle="bold"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="251dp" />
<Spinner
android:id="#+id/deporte"
android:layout_width="240dp"
android:layout_height="25dp"
android:layout_alignStart="#+id/textView7"
android:layout_below="#+id/textView7"
android:layout_marginLeft="35dp"
android:layout_marginTop="25dp"
tools:layout_editor_absoluteX="25dp"
tools:layout_editor_absoluteY="338dp"/>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/relativeLayout"
android:layout_marginStart="28dp"
android:layout_marginTop="23dp"
android:text="#string/seleccionaAct"
android:textColor="#color/colorPrimary"
android:textSize="18sp"
android:textStyle="bold"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="84dp" />
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#color/colorPrimaryDark"
android:layout_alignParentEnd="true">
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/nuevoAct"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="30sp"
android:textStyle="bold"
tools:text="#string/nuevoAct" />
</RelativeLayout>
<ImageButton
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:elevation="0dp"
app:srcCompat="#drawable/btnsig" />
</RelativeLayout>
The image is a png file whose dimesiones are 80x80 (32 bit color) 5.1k.
I do not know if the problem will have to do with some attribute of the layout of width or height that has as value match parent.
Thanks.
Try this:
Set android:src="#drawable/btnsig" instead of app:srcCompat="#drawable/btnsig".
This will work, just tested.

Layout is Orientation =vertical when device rotate it wont work

I have the following layout set to Orientation = vertical. But when I rotate the emulator to Landscape, it show the Layout in Landscape.
I want the Layout be in orientation vertical even the device rotate to Landscape.
How to solve this problem? Appreciate your help.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/myLinearLayout"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:id="#+id/myLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Put Your Name here :" />
<EditText
android:id="#+id/myEditBox"
android:inputType="textMultiLine"
android:textColor="#android:color/background_dark"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/myButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hey! Click Me" />
</LinearLayout>
android:orientation="vertical" means that the children are inserted into the layout vertically. So when you add more views they will stack underneath each other.
Vertical:
Horizontal:
This is the layout I used. Try change the orientation on your own and see the effect:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View
android:background="#aabbdd"
android:layout_width="50dp"
android:layout_height="50dp" />
<View
android:background="#341233"
android:layout_width="50dp"
android:layout_height="50dp" />
<View
android:background="#123456"
android:layout_width="50dp"
android:layout_height="50dp" />
<View
android:background="#654321"
android:layout_width="50dp"
android:layout_height="50dp" />
<View
android:background="#550000"
android:layout_width="50dp"
android:layout_height="50dp" />
</LinearLayout>
If you want to lock rotation in your Activity, you need to add the following property to your ActivityAttribute:
ScreenOrientation = ScreenOrientation.Portrait
So it will look something like:
[Activity(Label = "Herp Derp", ScreenOrientation = ScreenOrientation.Portrait)]
public class HerpDerpActivity : Activity
{
// more stuff here
}

Resources