I recently included the RatingBar view into a layout and realized it is not compatible with Talkback (it is not accessible). How can I have a star rating view that takes into account Talkback users?
Here are some ideas for anyone else who ends up here. I'm using targetSdk=28 and the androidx libraries.
Problem 1: Talkback skips the RatingBar when announcing the content in a ViewGroup.
Solution: Add a TextView with the desired announcement. Make it 0dp, so it won't affect your layout. INVISIBLE or GONE won't work.
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:text="4.1 of 5 stars"/>
Solution: Display the number of ratings, and add the stars to the contentDescription. (do it programmatically, though)
<TextView
android:id="#+id/ratingCountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="23"
android:contentDescription="4.1 of 5 stars from 23 users"/>
Problem 2: Tapping on a RatingBar to hear the value. contentDescription works in this case, and you can set it in code.
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="3.5"
android:stepSize="1"
android:contentDescription="4.1 of 5 stars"/>
Tapping and dragging on a RatingBar to change the value seems to work. It says 20%, 40%, 60%.
I found an example of what I need here:
https://github.com/google/iosched/blob/2017/lib/src/main/java/com/google/samples/apps/iosched/ui/widget/CustomRatingBar.java
Related
I'm developing an Android App that needs to be support Arabic language. (Which should be read from Right To Left). After quick googled the solutions, I figure out android fully support Arabic language natively in API level 17 with the declaration of
android:supportsRtl="true"
in the application tag inside of the AndroidManifest so that I can use the layout mirroring to automatically flip the layout for better right to left reading experience. However, I've noticed there is an issue happening while I use centerInParent in a view that inside of a sub RelativeLayout during the layout mirroring. Below are my codes and expected layout.
<RelativeLayout
android:background="#color/white"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:padding="20dp">
<RelativeLayout
android:background="#drawable/shape_flag_imageview_boarder"
android:id="#+id/imageLayout"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_height="100dp"
android:layout_width="100dp"
android:visibility="invisible" />
<ProgressBar
android:id="#+id/progressbar"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</RelativeLayout>
<TextView
android:id="#+id/text"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:layout_toEndOf="#id/imageLayout"
android:layout_width="wrap_content"
android:text="Some text here bla bla bla"
android:textColor="#color/black" />
</RelativeLayout>
Image above showing the expected result in normal layout direction which is Left to Right. The purpose I wrap the ImageView and ProgressBar together in a sub view is because I want the ProgressBar showing in the middle of the ImageView while the image is loading from the internet. After the I've changed Locale to Arabic, it becomes like
As I've try and error and figure out that this is causing by the centerInParent of the ProgressBar. It instead of centering inside the sub view, it align center to the root parent view which is the most outer RelativeLayout. Below is the screen shot of removing centerInParent code from the ProgressBar.
It clearly shows the layout mirroring works good, but the ProgressBar position is not what I'm expected. So I've try to work on centerVertical and centerHorizontal, the result are shown in images below respectively.
None of the solutions works, and none of the topic I've searched related to this issue. So I guess this might be a bug from Android library? If anyone knows the issues or solutions, please share to me. Thanks
I fixed it by adding android:layoutDirection="ltr" into the child RelativeLayout. Basically, it deactivates the RTL formatting for this particular RelativeLayout, and the android:layout_centerInParent="true" behaves correctly again. It solves our particular issue as our particular RelativeLayout contains only centred elements. But this trick should not be used if the Layout contains other elements which have to support correctly RTL, like text views for example. Hope it helps.
This is an RTL layout bug in the Android framework, which only affects Android 4.2 specifically (API 17) and when android:supportsRtl="true" is enabled in AndroidManifest.xml.
It happens when you use a RelativeLayout that contains items positioned with android:layout_centerVertical="true" or android:layout_centerInParent="true".
You can fix it in Java code like this:
View relativeLayout = layoutInflater.inflate(R.layout.my_relative_layout, parent, false);
// Fix RTL layout bug on Android 4.2 (for Arabic and Hebrew mode)
if (Build.VERSION.SDK_INT == 17 &&
getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
// Force a left-to-right layout
relativeLayout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
let me tell you correct answer, look your RelativeLayout(id:imageLayout),it's width is wrap_content, and your ProgressBar(id:progressbar) add an attribute android:layout_centerInParent="true".It means parent not limit witdh,and child also want to center,so parent will be stretched.
Suddenly occurs problem with custom fonts.
When i apply comic font for text views,first letter is cut. I try to implement paddings and margins but unfortunately still first letter is cut.
Images that are presented describe this problem.
I consider this flow as well but no results.
This is xml textview implementation.
<com.alllarm.alllarm.AutoResizeTextView
android:id="#+id/settings_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/my_profile"
android:textColor="#android:color/white"
android:textSize="35sp" />
This issue is connected with wrong size of the textview.To solve this problem you need just adjust additional size to the textview item. Additionally this could be connected with wrong text font feature.
I use RelativeLayouts extensively in my app and thought I knew how to specify them, but this has me at a loss. I am basically positioning 4 TextViews in two rows of two each consisting of a label and text that will be supplied. It should look something like:
Born: 23 Aug 1810 Mason Co., Kentucky
Died: 15 Jul 1865 Cincinnati, Hamilton Co., Ohio
This is the relevant portion of the layout:
<TextView android:id="#+id/birth_lbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/given_layout"
android:layout_alignLeft="#+id/given_layout"
android:layout_marginTop="6dip"
style="#style/label"
android:text="#string/born"
/>
<TextView android:id="#+id/birth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/birth_lbl"
android:layout_alignBaseline="#+id/birth_lbl"
android:layout_marginLeft="10dip"
android:layout_marginRight="6dip"
style="#style/main_text"
android:text="dd Mmm yy"
/>
<TextView android:id="#+id/death_lbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/birth"
android:layout_alignLeft="#+id/birth_lbl"
android:layout_marginTop="4dip"
style="#style/label"
android:text="#string/died"
/>
<TextView android:id="#+id/death"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/death_lbl"
android:layout_alignLeft="#+id/birth"
android:layout_alignBaseline="#+id/death_lbl"
android:layout_marginRight="6dip"
style="#style/main_text"
android:text="dd Mmm yy"
/>
For some reason, this displays the death line views ABOVE the birth line views! If I change the spec of the death_lbl view to instead be 'layout_below="#+id/birth_lbl"', the lines are positioned correctly! However, it is possible for the "birth" view to wrap to multiple lines, so I really need to position the 2nd line below "birth", not "birth_lbl".
Anyone know the reason for this behavior? It occurs both in the Graphical Layout editor in Eclipse and at runtime on my tablet running Android 4.0.
Try changing android:layout_below="#+id/birth" in death_lbl to android:layout_below="#id/birth", because at this point it is already declared, which the + implies, it could lead to problems when declaring it again.
I was also facing the same problem because I was using constraint layout, but align_below works only in Relative Layout. so check which layout you are using.
If fixing your + signs doesn't help, you could always position your id/death below id/birth, and then put id/death_label toLeftOf id/death.
I was actually able to duplicate this phenomenon by coding up a temporary layout with only those fields, and was able to determine that the problem went away if I did not position the initial birth_lbl view relative to the view above it ("given_layout" in this case).
So I'm not sure if this is classified as a fix, a workaround, or a kludge (is that still a word these days?), but what I did was to position the text views inside their own RelativeLayout and position the RelativeLayout relative to id/given_layout. In any case, it works...
Your problem is that you are calling the properties on the relative layout as if though you are declaring it again.
When you declare an ID for a view then it should be done like this android:id="#+id/button"
and when you want Android to position that particular view above or below any other view in a relative layout you have to call it like this android:layout_below="#id/textview"
This tells android that you declared a button with id button and want it to be positioned below the textview, remember do not use #+id to postion view use #id instead.
I have a button. It seems to have bottom padding I cannot get rid of:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Foo"/>
In the resource editor, I can click the button, and you see the padding below the bottom edge of the button there. This seems to block me from properly centering the button vertically in a parent RelativeLayout.
I tried setting padding=0dip and layout_margin=0dip, no effect. That bottom padding persists.
Thanks
The padding is in the 9-patch of the buttons themselves.
I'd advise against trying to compensate because these graphics resources can change without notice. You'd be better off building your own 9-patch or editing the existing one to remove the padding.
setting android:layout_marginBottom="-5dp" for the button worked nicely for me.
I am late to answer this but thought to share if someone come across similar use case( Removing all the inner and outer padding in Button )
<Button
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-5dp"
android:layout_marginLeft="-5dp"
android:layout_marginRight="-5dp"
android:layout_marginTop="-5dp"
android:minHeight="-2dp"
android:minWidth="-2dp"
android:text="TextView"
android:textSize="12sp" />
Hmn really strange. Never noticed that. Probably because u usally want a little space around your buttons.
Also tried margin/padding=0dp and did in fact not work.
You could set android:layout_marginBottom="-10dp" however :).
Does any one know how to wrap text in TextView in Android platform. i.e if the text in textview exceed the screen length it should be displayed in the second line.
I have searched and tried the following:
android:scrollHorizontally="false",
android:inputType="textMultiLine",
android:singleLine="false"
But none work..
Can anyone suggest how can I do it.
Constraint Layout
<TextView
android:id="#+id/some_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="#id/textview_above"
app:layout_constraintRight_toLeftOf="#id/button_to_right"/>
Ensure your layout width is zero
left / right constraints are defined
layout height of wrap_content allows expansion up/down.
Set android:maxLines="2" to prevent vertical expansion (2 is just an e.g.)
Ellipses are prob. a good idea with max lines android:ellipsize="end"
0dp width allows left/right constraints to determine how wide your widget is.
Setting left/right constraints sets the actual width of your widget, within which your text will wrap.
Constraint Layout docs
For me this issue only occurred on Android < 4.0
The combination of parameters I used were:
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"
The maxLines count seemed to be the random final piece that made my TextView wrap.
For the case where the TextView is inside a TableLayout, the solution is to set android:shrinkColumns="1" on the TableLayout. (Replace 1 with the column number the TextView you want to wrap is in. (0-indexed))
AFAICT, no other attributes are needed on the TextView.
For other cases, see the other answers here.
FWIW, I had initially gotten it to sort of work with
<TextView
android:id="#+id/inventory_text"
android:layout_width="fill_parent"
android:layout_weight="1"
android:width="0dp"
but that resulted in some extra empty space at the bottom of the Dialog it was all in.
Use app:breakStrategy="simple" in AppCompatTextView, it will control over paragraph layout.
It has three constant values
balanced
high_quality
simple
Designing in your TextView xml
<android.support.v7.widget.AppCompatTextView
android:id="#+id/textquestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:scrollHorizontally="false"
android:text="Your Question Display Hear....Your Question Display Hear....Your Question Display Hear....Your Question Display Hear...."
android:textColor="#android:color/black"
android:textSize="20sp"
android:textStyle="bold"
app:breakStrategy="simple" />
If your current minimum api level is 23 or more then in Coding
yourtextview.setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE);
For more refrence refer this BreakStrategy
You must use 2 parameters :
android:ellipsize="none" : the text is not cut on textview width
android:scrollHorizontally="false" the text wraps on as many lines as necessary
This should fix your problem: android:layout_weight="1".
By setting android:maxEms to a given value together with android:layout_weight="1" will cause the TextView to wrap once it reaches the given length of the ems.
OK guys the truth is somewhere in the middle cause you have to see the issue from the parent's view and child's. The solution below works ONLY when spinner mode = dialog regardless of Android version (no problem there.. tested it in VD and DesireS with Android =>2.2) :
.Set you spinner's(the parent) mode like :
android:spinnerMode="dialog"
Set the textview's(child custom view) properties to :
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"
I hope this works for you also.
In Android Studio 2.2.3 under the inputType property there is a property called textMultiLine. Selecting this option sorted out a similar problem for me. I hope that helps.
Just was working on a TextView inside a layout inside a RecyclerView. I had text getting cut off, ex, for Read this message, I saw: Read this. I tried setting android:maxLines="2" on the TextView, but nothing changed. However, android:lines="2" resulted in Read this on first line and message on the 2nd.
Try #Guykun's approach
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"
Also, make sure that parents width is not set to wrap content. This is the thing that I was missing.
I had the same problem. Following change made it work -
android:layout_width="wrap_content"
The ellipsis, maxLines, or layout_weight - all didn't make any difference.
Note - The parent width is also set as wrap_content.
All you have to do is to set your textview width.
android:layout_width="60dp"
you can change the width to your choice. Just type long sentence to check if it working like this
android:text="i want to be among world class software engineer"
I am using Android 2.2 and my textview will automatically goto the next line if it exceeds the screen.
If you would like to have the text goto the next line before the end of the screen, just add in (just put in your own dp value). This will be useful if you have a picture on the right of the text.
android:layout_marginRight="52dp"
Strange enough - I created my TextView in Code and it wrapped - despite me not setting anything except standard stuff - but see for yourself:
LinearLayout.LayoutParams childParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
childParams.setMargins(5, 5, 5, 5);
Label label = new Label(this);
label.setText("This is a testing label This is a testing label This is a testing label This is a testing labelThis is a testing label This is a testing label");
label.setLayoutParams(childParams);
As you can see from the params definition I am using a LinearLayout. The class Label simply extends TextView - not doing anything there except setting the font size and the font color.
When running it in the emulator (API Level 9) it automatically wraps the text across 3 lines.
Just set layout_with to a definate size, when the text fills the maximum width it will overflow to the next line causing a wrap effect.
<TextView
android:id="#+id/segmentText"
android:layout_marginTop="10dp"
android:layout_below="#+id/segmentHeader"
android:text="You have the option to record in one go or segments(if you swap options
you will loose your current recordings)"
android:layout_width="300dp"
android:layout_height="wrap_content"/>
The trick is with the textView width, try to make it dedicated number like:
<TextView
android:layout_width="300dp"
android:layout_height="wrap_content"/>
I've tried many solutions without any result, I've tried:
android:ellipsize="none"
android:scrollHorizontally="false"
the only one thing triggred the wrap option is the dedicated width
You need to add your TextView in a ScrollView with something like this :
<ScrollView android:id="#+id/SCROLL_VIEW"
android:layout_height="150px"
android:layout_width="fill_parent">
<TextView
android:id="#+id/TEXT_VIEW"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header" />
</ScrollView>