I would Insert a text on image button in kottlin - android-studio

I want to put a text right in the middle of my button, but only with the possible button, but I have an image button
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="469dp"
android:layout_height="171dp"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/imageView6"
app:layout_constraintHorizontal_bias="0.532"
app:layout_constraintStart_toStartOf="#+id/imageView6"
app:layout_constraintTop_toTopOf="#+id/imageView6"
app:layout_constraintVertical_bias="0.16"
app:srcCompat="#drawable/bodybalance_desktop_fw20_com_selects_artworking2_960x560" />

Use a button on top of the imagebutton and set the backgroundTint of the button to null so it becomes transparent and only shows the text on it

Related

Always make the prefix text in text input layout visible like the hint

I am having a prefix text in a Text Input Layout but it only shows when i click inside the Text Input Edit Text which is inside the Text Input Layout that has my prefix text. How can i make the prefix text to always show with the hint
Below is my Text Input Edit Text
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/til_number"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/til_country"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="10dp"
android:padding="5dp"
app:boxBackgroundColor="#EFEFF2"
app:prefixText="+01 - "
app:shapeAppearanceOverlay="#style/RoundedTextInputLayout">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/et_first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="#string/number"
android:inputType="phone"
android:maxLength="100"
android:textSize="15sp" />
</com.google.android.material.textfield.TextInputLayout>
What i would like to achieve is
+01 - 
the above text in prefix should always show
i have tried doing the following below
app:prefixTextColor="#color/secondaryDarkColor"
If you check the logic of the view, you will see the prefix text will be hidden if:
prefixTextView.setVisibility((prefixText != null && !isHintExpanded())
? VISIBLE : GONE);
Add app:expandedHintEnabled="false" to your TextInputLayout and your prefix text will stay visible:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/text_input_layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:expandedHintEnabled="false"
app:prefixText="MyPrefix: ">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/text_input_edit_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="My optional Hint" />
</com.google.android.material.textfield.TextInputLayout>
Note: Of course the hint will show on top like this.
From the Material.io website, you can use:
Adding a prefix/suffix to a text field: app:prefixText="#string/prefix"
Inside your com.google.android.material.textfield.TextInputLayout.
The Android Studio preview will not show the prefix in the text view but if you run the application on a device, when the user selects the input text, the prefix will be shown. Below there are the screenshots of what i tested.
With the input layout not selected
With the input layout selected (my_prefix if what i used as text prefix in the xml, and typed text is what i added from the keyboard)
If you want to show the suffix when the hint is not expanded using Kotlin:
textInputLayout.viewTreeObserver.addOnGlobalLayoutListener {
textInputLayout.suffixTextView.visibility = View.VISIBLE
}

How to slide Text from left to right using marquee

I am using marquee.In my Android app Say original value pf text view is aaabbbccc and its fitting inside the view. So my marquee's output will be : aaabbbccc auto sliding from right to left. But instead of this i want to slide this aaabbbccc auto sliding from left to right. How can i do this....Below is my xml file.Thanks`
android:id="#+id/txt_MainScreen_Winnerlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginLeft="-10dp"
android:layout_marginTop="0dp"
android:layout_marginRight="20dp"
android:ellipsize="marquee"
android:focusable="false"
android:focusableInTouchMode="false"
android:fontFamily="#font/proximanovaregular"
android:gravity="center"
android:marqueeRepeatLimit="marquee_forever"
android:paddingTop="2dp"
android:paddingRight="25dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Exchange1:(00.14-2.30) Exchange2:(01.00-2.30) Exchange3:(05.00-6.30) Exchange4:(12.14-2.30) Exchange5:(10.00-12.30) Exchange6:(00.30-2.30) Exchange7:(03.00-05.00) "
android:textSize="13dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />`
Default system scrolls from right to left. Use animation for left to right scroll.
Animation animationl2r = new TranslateAnimation(-400,400, 0, 0);
animationl2r.setDuration(12000);
animationl2r.setRepeatMode(Animation.RESTART);
animationl2r.setRepeatCount(Animation.INFINITE);
TextView textview = findViewById(R.id.textview);
textview.setAnimation(animationl2r);
Resize the screen area by changing 400 to any other value and duration to your desired time.

How get width of text show in textview - not all text, just text on screen

I have a textview:
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Big ideas for a better life"
android:singleline:"true"
android:id="#+id/show1" />
because singleline and width=100dp, my textview only show
Big ideas for a
how to mesure width of "Big ideas for a"
or
how to know the text show "Big ideas for a"
????
You should use android:layout_width="wrap_content" instead

Making a stackable, square graph with text labels

For my first venture into Android-land, I have what seems to me to be a simple project. I want to display a square graph with text in its four corners. I want to be able to display a single graph, or four, grouped 2 x 2.
Quad graph example
So far, the only means I've found to overlay the four TextViews on my custom GraphView is to put the GraphView in a RelativeLayout, and position the TextViews relative to it.
<?xml version="1.0" encoding="utf-8"?>
<com.companyname.graph.GraphLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<com.companyname.graph.GraphView
android:id="#+id/graph_single_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/colorGraphBackground"
/>
<TextView
android:id="#+id/label_top_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/graph_single_view"
android:layout_alignStart="#+id/graph_single_view"
android:layout_alignTop="#+id/graph_single_view"
android:layout_gravity="top|start"
android:gravity="top|start"
android:hint="#string/placeholder_top_left"
/>
<TextView
android:id="#+id/label_top_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/graph_single_view"
android:layout_alignRight="#+id/graph_single_view"
android:layout_alignTop="#+id/graph_single_view"
android:layout_gravity="top|end"
android:gravity="top|end"
android:hint="#string/placeholder_top_right"
/>
<TextView
android:id="#+id/label_bottom_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/graph_single_view"
android:layout_alignLeft="#+id/graph_single_view"
android:layout_alignStart="#+id/graph_single_view"
android:layout_gravity="bottom|start"
android:gravity="bottom|start"
android:hint="#string/placeholder_bottom_left"
/>
<TextView
android:id="#+id/label_bottom_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/graph_single_view"
android:layout_alignEnd="#+id/graph_single_view"
android:layout_alignRight="#+id/graph_single_view"
android:layout_gravity="bottom|end"
android:gravity="bottom|end"
android:hint="#string/placeholder_bottom_right"
/>
</com.companyname.graph.GraphLayout>
To keep the GraphView square, I'm doing this in the GraphView class:
#Override
protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec )
{
super.onMeasure( widthMeasureSpec, heightMeasureSpec );
int size = Math.min( getMeasuredWidth(), getMeasuredHeight() );
setMeasuredDimension( size, size );
}
(stolen from here).
I'm running into problems, though, in displaying the group of four. GridLayout loses its tiny mind at the thought (it puts every GraphView in an area the width of the entire screen). I ended up using two horizontal LinearLayouts in a vertical LinearLayout, sized using layout_weight, which works, but won't let me do the animated transition that I want. I'd like a single graph simply to expand to cover the entire area, clipping its unchanging siblings as it goes, and back again.
So far I've settled on animating the layout_weights in the LinearLayouts, but the effect isn't something you'd show off to your friends.
I'm using height and width of WRAP_CONTENT for everything except 1dip-wide/tall separator lines between the graphs in the two rows, and between the rows in the quad view.
So my (first) question is - is there a better way to make my graph-plus-text widget?

Align 3 stretched Textview in a row in Relative Layout prgramatically

Please don't mark this question as duplicate. Why? because I am going to explain why it's not.
Below are the steps I have done:
Create a RelativeLayout
Created LayoutPArams for it as wrap_content and wrap_content
Created 1st TextView , gave it an id
Created LayoutParams for first textview and added it to the RelativeLAyout
Created Second TextView
Created LayoutParams for it, added a rule to be right_Of of id_for_first_tetview
Same step for Third Textview, except it's right_of the second textview
The problem here is: The first text view has text which extends to the second line, and when the text extends to the second line, the width of this i.e. the first textview occupied the whole width, and hence the other textview either overlaps or comes below it.
Let me demonstrate that with a diagram:
Want:
Happening:
So in short, is there a way to keep the textviews in one row and even if one textview takes up two rows, the second textview can start right after where the text for forst Textview ended ?
Thank you in advance. I could really use some help.
This can be done with LinearLayout with weight easily.
Method 1 - XML (give required padding or margins)
<LinearLayout
android:layout_width="match_parent"
android:weightSum="3"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextViewTextViewTextViewTextView" />
<TextView
android:id="#+id/textView4"
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
Method 2 - Programmatically (give required padding or margins)
tv2 = (TextView)findViewById(R.id.textView2);
tv3 = (TextView)findViewById(R.id.textView3);
tv4 = (TextView)findViewById(R.id.textView4);
android.widget.LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1f);
tv2.setLayoutParams(params);
tv3.setLayoutParams(params);
tv4.setLayoutParams(params);

Resources