I have done the seekbar but I need to do the customization like the below image.
I used the code like this
<SeekBar
android:id="#+id/seekbarPoints"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="-16dp"
android:layout_marginTop="#dimen/small"
android:max="0"
android:progress="0"
android:progressDrawable="#drawable/shape_seekbar_points_style"
android:thumb="#null" />
if (TextUtils.isDigitsOnly(maxPoints)) {
int maxP = Integer.parseInt(maxPoints);
mBinding.seekbarPoints.setMax(maxP);
if (!TextUtils.isEmpty(points)) {
int p = (int) Double.parseDouble(points);
mBinding.seekbarPoints.setProgress(p);
}
}
mBinding.seekbarPoints.setProgressDrawable(ContextCompat.getDrawable(getContext(), R.drawable.shape_seekbar_points_style));
In this image there should be a current points showing textView like the image below
Please suggest some solution for this
Thanks in advance.
you can use following library to achieve your goal
take a look below libray
Library 1
Library 2
Library 3
Library 4
Related
I'm trying to make a game like a "click & kill" and I'm trying to make a health bar for the character to kill.
I'm using a simple image (a red rectangle) and I would like to reduce the health bar after one click. What I tryed works but the problem is not just the with decrease, the height too. So the result is really horrible. To begin, this is my XML (I only show one for example):
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="33">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFF00"
android:id="#+id/hole4"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/healthBar4"
android:src="#drawable/health_bar"/>
</RelativeLayout>
So here nothing bad (I think) I leave android:adjustViewBounds="true" because I thought the problem came from here.
Next is my Activity :
final int healthBarHeightInitial = healthBar4.getLayoutParams().height;
final int healthBarWidthInitial = healthBar4.getLayoutParams().width;
healthBar4.requestLayout();
//ivHole4 is my ImageView I get the click to leave some life to the character
ivHole4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//If character die (works great).
if(choixAction.ChoixAction(CharaHole4,outil)){
Log.d("Perso","Character is die");
mAvancement +=1;
ivHole4.setImageResource(0);
CharaHole4 = null;
placeChara.setHole4(true);
healthBar4.setVisibility(View.GONE);
healthBar4.getLayoutParams().height = healthBarHeightInitial;
healthBar4.getLayoutParams().width = healthWidthInitial;
}
//if character don't die (here is the problem !)
else {
healthBar4.getLayoutParams().width = healthBar4.getWidth()/2; //This is works great
healthBar4.getLayoutParams().height = healthBarHeightInitial; //This is do nothing, the height is /2 too.
healthBar4.requestLayout();
}
}
});
I hope someone know how to change the image size not proportionally.
Thank's advance.
Your ImageView in the XML Layout needs to set the scale type to fitXY to allow it to expand without keeping proportions.
android:scaleType="fitXY"
Use Picasso Library and set Crop Center.
I need to hide the domain values in a linegraph. Could someone please help me?
plot0.setDomainBoundaries(0, windowsize, BoundaryMode.FIXED);
plot0.addSeries(series0, formatter);
plot0.setDomainStepMode(XYStepMode.INCREMENT_BY_VAL);
plot0.setDrawRangeOriginEnabled(true);
plot0.setTicksPerRangeLabel(5);
plot0.getLegendWidget().setVisible(false);
plot0.getGraphWidget().getBackgroundPaint().setColor(Color.BLACK);
plot0.getGraphWidget().getGridBackgroundPaint().setColor(Color.BLACK);
plot0.setTicksPerDomainLabel(5);
plot0.centerOnRangeOrigin(0);
plot0.setRangeBottomMax(-20);
plot0.setRangeTopMin(20);
plot0.setRangeLowerBoundary(-75, BoundaryMode.FIXED);
plot0.setRangeUpperBoundary(75, BoundaryMode.FIXED);
plot0.setRangeStep(XYStepMode.INCREMENT_BY_VAL, 25);
plot0.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 240);
UPDATE:-
Library version
compile 'com.androidplot:androidplot-core:0.9.7'
I have modified the XML with as below. But the changes are not reflecting unless I modify it inside the code.
<com.androidplot.xy.XYPlotZoomPan
android:id="#+id/dynamicXYPlot0"
androidplot.renderMode="use_background_thread"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginTop="20dp"
android:background="#android:color/black"
ap:backgroundColor="#000000"
ap:borderColor="#000000"
ap:label="Lead I"
ap:domainTickLabelTextColor="#00000000"
ap:domainOriginTickLabelTextColor="#00000000"
ap:gridPaddingBottom="1dp"
ap:labelTextSize="10sp" />
I'd suggest trying to do it in XML by adding these params:
ap:domainTickLabelTextColor="#00000000"
ap:domainOriginTickLabelTextColor="#00000000"
ap:gridPaddingBottom="1dp"
This basically sets the tick label color to be completely transparent and removes the extra padding needed to display those labels below the grid.
Before:
After:
Got the solution. Adding these 2 lines worked.
plot0.getGraphWidget().getDomainTickLabelPaint().setColor(Color.TRANSPARENT);
plot0.getGraphWidget().getDomainOriginTickLabelPaint().setColor(Color.TRANSPARENT);
I have been struggling with this for far too long. I want to display the nerd face http://emojipedia.org/nerd-face/ but am unsure how to go about it:
This is the current XML I have:
<com.rockerhieu.emojicon.EmojiconTextView
android:id="#+id/txtEmojicon1"
android:text=""
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:textIsSelectable="true"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="44dp"
android:layout_marginStart="44dp" />
I have no idea what to place inside the android:text=""
Everything I place inside of the text="" comes out to not working
UPDATE THIS LIBRARY HAS BEEN DISCONTINUED BY THE OWNER UPDATE
see here : https://github.com/rockerhieu/emojicon
its pretty easy for you to implement any emoji type from Rockerheiu .
1.You will have to add the library as a module unlike adding it via the maven central Repository .
Once you are done adding module
Navigate to the library -> library\src\main\java\io\github\rockerhieu\emojicon\emoji and you edit the People.java File to get started on adding a new emoji code looks like this.
package io.github.rockerhieu.emojicon.emoji;
/**
* #author Hieu Rocker (rockerhieu#gmail.com)
*/
public class People {
public static final Emojicon[] DATA = new Emojicon[]{
Emojicon.fromCodePoint(0x1f604),
Emojicon.fromCodePoint(0x1f603),
Emojicon.fromCodePoint(0x1f600),
Emojicon.fromCodePoint(0x1f60a),
Emojicon.fromChar((char) 0x263a),
Emojicon.fromCodePoint(0x1f609),
Emojicon.fromCodePoint(0x1f60d),
Emojicon.fromCodePoint(0x1f618),
I am learning Android and the following is part of an assignment.
I need to write some text in an Android layout with the first letter in drop caps, like the following text:
I looked up the web and did not find many answers. Is there a style option or some property that I could use?
At the moment, I am thinking of the following options. Please suggest what is the best way to do such a thing
Use an image for the first letter
Write the first letter separately in a big font.
Any suggestions would be helpful.
You can use a RelativeSizeSpan.
final String someText = "A long time ago in a galaxy far, far away";
final SpannableString ss = new SpannableString(someText);
ss.setSpan(new RelativeSizeSpan(5f), 0, 1, 0);
There's a library written by Novoda in which you can add a DropCap https://github.com/novoda/spikes/tree/master/drop-cap
Here's an image from the demo app:
Please follow GitHub sample app
https://github.com/datanapps/CapTextView
<datanapps.captextview.CapTextView
android:id="#+id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:padding="5dp"
app:layout_constraintTop_toBottomOf="#+id/text1"
app:capsDropNumber="2"
app:capFont="#font/eb_garamond_regular"
app:capTextColor="#color/purple_700"
app:capTextSize="#dimen/cap_text_size"
app:bodyTextColor="#color/purple_700"
app:bodyTextSize="#dimen/body_text_size"
app:bodyTextFont="#font/eb_garamond_regular"
/>
Hope it will help
I am currently trying to draw a graph within an Android application. The library I found is called GraphView (http://www.jjoe64.com/p/graphview-library.html). I am currently using version 2, which is available on GitHub.
Drawing graphs works really nicely. The code necessary to get a graph is the following:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Map<String,List<GraphEntry>> graphData = (...)
if (graphData != null) {
List<GraphEntry> entries = graphData.get("temperature");
GraphView.GraphViewData[] data = new GraphView.GraphViewData[entries.size()];
int i = 0;
for (GraphEntry entry : entries) {
data[i++] = new GraphView.GraphViewData(entry.getDate().getTime(), entry.getValue());
}
GraphView.GraphViewSeries graphViewSeries = new GraphView.GraphViewSeries("temperature", 0xffff0000, data);
LineGraphView graphView = new LineGraphView(this, "temperature");
graphView.addSeries(graphViewSeries);
graphView.setShowLegend(true);
LinearLayout graphLayout = (LinearLayout) findViewById(R.id.layout);
graphLayout.addView(graphView);
}
}
This will produce a normal graph. Unfortunately, all kinds of labels are missing. The documentation tells that for the normal use case, one does not have to care about labels, as the library does this automatically. What am I doing wrong? I only get the plain graph, without any labels.
For the completeness, I am adding the graph to a linear layout. The appropriate layout file has the following contents:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:padding="5dp"
android:id="#+id/layout"
android:orientation="vertical"
></LinearLayout>
The GraphEntry class is only a container with a java.util.Date attribute and a double value attribute.
Thank you very much for any help,
Matthias
I switched to another charting engine: AChartEngine. This one works out of the box.
I had the same problem. This can be solved by removing the following line from the manifest file.
android:theme="#style/AppTheme"
I know this is quite vague, but worked for me. I don't the exact reason why this happens. If u guys come across the better solution please do share it.
You should use the latest version from github and include that in your project. This will allow you to set various colours using
graphView.getGraphViewStyle().setGridColor(Color.GREEN);
graphView.getGraphViewStyle().setHorizontalLabelsColor(Color.YELLOW);
graphView.getGraphViewStyle().setVerticalLabelsColor(Color.RED);