How do you add padding to the left of NumberPicker items, resulting in something similar to the picture below.
I was able to add whitespace using RelativeLayouts, but there are issues with that. (mainly that the added RelativeLayout doesn't detect scroll gestures)
I think I need to extend NumberPicker and do something, but I'm not sure what.
Here is my NumberPicker xml:
<NumberPicker
android:id="#+id/pars_left_numberPickerID"
android:background="#color/white"
android:descendantFocusability="blocksDescendants"
android:elevation="10dp"
android:gravity="center"
android:layout_height="190dp"
android:layout_width="90dp"
android:orientation="vertical"
android:theme="#style/numberPicker"
android:visibility="visible" />
`android:paddingLeft="10dp"`
Just type padding and explore ther options.
After giving up on the default NumberPicker, I was able to get this working by importing and modifying this 3rd party NumberPicker: https://github.com/Carbs0126/NumberPickerView
This allowed me to create a paddingLeft attribute that the number picker will respect.
Replace the width being statically set with android:layout_width="90dp" (the reason why it even looks wonky) with wrap_content and you might not be facing this home-made problem. Besides, Widget.Material.NumberPicker can be styled to some degree.
Related
This question already has answers here:
How to include layout inside layout?
(6 answers)
Closed last year.
I have my main activity. Inside this main activity I want to create an unknown number of layouts that each one of them include one button.
I want smart way to do it - make the layout one time and than use it a lot of time.
What is a good way to do it?
Thanks
Make One Layout Resource File Using Below Code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="#dimen/_100sdp"
android:layout_marginTop="#dimen/_15sdp"
android:gravity="center"
android:textColor="#color/black"
android:textSize="#dimen/_13sdp" />
<Button
android:layout_width="match_parent"
android:layout_height="#dimen/_35sdp"
android:layout_marginStart="#dimen/_5sdp"
android:layout_marginTop="#dimen/_20sdp"
android:layout_weight="1"
android:gravity="center"
android:text="Submit"
android:textColor="#color/white"
android:textSize="#dimen/_10sdp" />
</LinearLayout>
And In Your Main Activity Layout You Can Use Only
<include layout="#layout/layoutresourcefilename"/>
Trying to be smart commonly results in the opposite. Better keep it simple;
Which means, just add three buttons and then show either one of them.
This has the advance, that the events are already bound, ready to click.
And also, meanwhile it's a whole lot more common to inflate Fragment
or to data-bind views, which would permit for hiding/showing buttons.
I am making chatting app and want to style messages as they are in messenger app.
And this is my code to style them:
textView.setTextColor(Color.parseColor("#FFFFFFFF"));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(400,0,10,10);
params.gravity = Gravity.END;
textView.setLayoutParams(params);
linearLayout.addView(textView);
This is my XML code:
<ScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="12dp"
android:background="#drawable/background"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toTopOf="#+id/editTextTextPersonName2"
app:layout_constraintTop_toBottomOf="#+id/name">
<LinearLayout
android:id="#+id/chatMessages"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
And my TextViews are added to this ^ linear layout.
And this is what I am receiving in app: (don't translate messages they are only for test purposes and they are stupid)
And I do not why those gaps are made, someone please help me.
It is the normal behavior of textView. You can test on the SIGNAL app by typing a long word and it will move it to the next line and on the upper line, you will get to see the same space left as you are getting in yours.
If you mean to change the alignment of text in the textview then you can define the textAlignment property of textView according to your requirement.
That's happening because of the long length of the last word of your messages, if Android sees that he can't put a sequence of chars (word) into the current line, then it types it down on the next one, so to solve this problem you have 2 different solutions (or more):
1- But it may live a gap from the other side
textView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_END);
2- It centers the text in its container which may live a gap from both sides
textView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
Good luck.
I'm trying to understand what is the meaning of android:orientation attribute in layout xml file as part of ConstraintLayout
In The code:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="150dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:orientation="horizontal"
As far as I know, each valid attribute as a "meaning" but when changing between horizontal and vertical values nothing really change.
Don't I understand correctly the meaning of orientation or my assumption that each attribute as a meaning is incorrect?
It is actually not doing anything, it is a redundant attribute.
This question already has answers here:
How to reduce the space around rating bar in android
(3 answers)
Closed 4 years ago.
i have rating bar on my application and it appears like this:
I've tried to set padding to 0dp, but nothing changed to the view.
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:layout_marginStart="16dp"
android:isIndicator="false"
style="#style/Widget.AppCompat.RatingBar"/>
Expected result: I am expecting the rating bar with no right padding and bottom padding.
You can simply adjust this
style="#android:style/Widget.DeviceDefault.RatingBar.Small"
instead of
style="#style/Widget.AppCompat.RatingBar
I add this to my xml code and it solved my problems:
android:scaleX="1"
android:scaleY="1"
The built-in Android rating bar is very visually problematic, in which case I would rather use the improvements made by Android users to size each star depending on the size of the object.
Enclosing you a convenient library to work with, I believe this library will solve you a lot of problems with the development.
https://github.com/xckevin/AndroidSmartRatingBar?utm_source=android-arsenal.com&utm_medium=referral&utm_campaign=7405
Credit to the developer kevin.liu (xckevin).
use scale x and y to reduce the start size and step size to set star size
Try this xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:isIndicator="false"
style="#style/Widget.AppCompat.RatingBar" />
</LinearLayout>
I want to have a "comments" button on my Android e-reader app that displays the number of comments currently posted inside the icon... so basically I want a comment bubble with a number inside it.
I could have multiple drawables, each being the bubble with a different number inside of it, and use a switch statement to choose which one to load each time based on the int number_of_comments field of the element being displayed. This approach seems a little wasteful though, and in any case I have a feeling there's a more elegant way to do it.
Any ideas?
You can do better. You can have a textview on top of the image view and keep updating its value everytime a new comment is added. You can define the overlap in xml like below and adjust your code logic accordingly to increase the comment count. For now I have just set up a dummy text Hello to show on top of the ImageView. You can add your comment count using the TextView's setText method.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativelayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myImageSouce" />
<TextView
android:id="#+id/myImageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/myImageView"
android:layout_alignTop="#+id/myImageView"
android:layout_alignRight="#+id/myImageView"
android:layout_alignBottom="#+id/myImageView"
android:layout_margin="1dp"
android:gravity="center"
android:text="Hello"
android:textColor="#000000" />
</RelativeLayout>
Hope this helps...
check out this 3rd party created widget
Android ViewBadger
You can use it to create the little number bubbles that you are looking for I think. This gives you the benefit of not having modify your layouts so much to achieve what you are trying to get.
Here is the sample code to apply a "badge"
View target = findViewById(R.id.target_view);
BadgeView badge = new BadgeView(this, target);
badge.setText("1");
badge.show();