I have textfield - text view in relative layout with rounded rectangle. It looks fine until I try to change textview to edit text. After it, text of EditText view is cutted of. Well, I try to change height to wrap_content, it fixes the problem of cutting, but the rounded rectangle becomes much higher than with textView although EditText height seems like only half of the rectangle outside. How can I remove these spaces below and above the real visible EditText? Any manipulations with margins/paddings don't help me.
EditText with wrap_content height:
EditText with 30dp height:
TextView with 30dp height:
<RelativeLayout
android:id="#+id/token_input_layout_outside"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/top_divider"
android:gravity="center_horizontal"
android:paddingVertical="5dp"
app:layout_constraintStart_toEndOf="#id/top_divider"
app:layout_constraintTop_toBottomOf="#id/top_divider">
<RelativeLayout
android:id="#+id/token_input_layout"
android:layout_width="#dimen/counter_monitor_width"
android:layout_height="30dp"
android:background="#drawable/counter_background_3"
android:gravity="center">
<EditText
android:gravity="center_horizontal"
android:id="#+id/token_input"
android:layout_width="85sp"
android:layout_height="match_parent"
android:maxLength="5"
android:singleLine="true"
android:textSize="23sp"
android:backgroundTint="#color/white"
android:textColor="#color/white"
android:hint="Input"
android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz">
</EditText>
</RelativeLayout>
</RelativeLayout>
30dp is a small height for your textSize; so you can do it in two different ways:
make edit text wrap_content:
<RelativeLayout
android:id="#+id/token_input_layout"
android:layout_width="#dimen/counter_monitor_width"
android:layout_height="wrap_content"
android:background="#drawable/counter_background_3"
android:gravity="center">
<EditText
android:gravity="center_horizontal"
android:id="#+id/token_input"
android:layout_width="85sp"
android:layout_height="wrap_content"
android:maxLength="5"
android:singleLine="true"
android:textSize="23sp"
android:backgroundTint="#color/white"
android:textColor="#color/white"
android:hint="Input"
android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz">
</EditText>
</RelativeLayout>
change height size:
<RelativeLayout
android:id="#+id/token_input_layout"
android:layout_width="#dimen/counter_monitor_width"
android:layout_height="wrap_content"
android:background="#drawable/counter_background_3"
android:gravity="center">
<EditText
android:gravity="center_horizontal"
android:id="#+id/token_input"
android:layout_width="85sp"
android:layout_height="30dp"
android:maxLength="5"
android:singleLine="true"
android:textSize="23sp"
android:backgroundTint="#color/white"
android:textColor="#color/white"
android:hint="Input"
android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz">
</EditText>
</RelativeLayout>
Related
How can I layout the two edit txt fields in the middle of the screen.
Current layout is not align to middle of the screen (its on the left).
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<EditText
android:id="#+id/edit_code_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="0"
android:inputType="number"
android:maxLength="1"
android:padding="10dp"
android:textSize="20sp"
/>
<EditText
android:id="#+id/edit_code_2"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="0"
android:inputType="number"
android:maxLength="1"
android:padding="10dp"
android:textSize="20sp" />
</LinearLayout>
You have used android:layout_gravity="center_vertical" so it's vertically centered. If you want it to be horizontally centered you can use
android:layout_gravity="center_horizontal"
or if you want both :
android:layout_gravity="center"
Update with comment :
This solution only works if you replace android:layout_width="match_parent" by android:layout_width="wrap_content" in your LinearLayout
You can make your Linear layout width as wrap_content
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
If its parent layout is Constraint Layout you can Constraint it to left and right side and LinearLayout will remain in middle.
Hi My textview is not moved into next line,Even i set maxlenght,maxsize also,Need to set imageview width based height,Sorry for my poor english
Here is my xml what i tried,
<RelativeLayout
android:id="#+id/rlTopview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/proimg"
android:layout_width="200dp"
android:layout_height="160dp"
android:background="#drawable/categoriesicon"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/txtcom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/proimg"
android:layout_marginLeft="5dp"
android:maxEms="23"
android:maxLines="2"
android:scrollHorizontally="false"
android:singleLine="false"
android:text="Learn and Understanding \Node JS"
android:textColor="#color/colorPrimaryBlack"
android:textSize="18dp" /></RelativeLayout>
Your <ImageView> tag has a defined width of 200dp. If what you want is for each card to be exactly 200dp wide, the image to fill the card, and the text below it to wrap if it's longer than 200dp, make these changes:
Change your RelativeLayout's width from match_parent to 200dp
Change your ImageView's width from 200dp to match_parent
Change your TextView's width from wrap_content to match_parent
First of all please remove the #+id from the TextView it should be only #id. Then back to your problem you have three approaches, either to set the ImageView to full width like this
<RelativeLayout
android:id="#+id/rlTopview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/proimg"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="#drawable/categoriesicon"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/txtcom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/proimg"
android:layout_marginLeft="5dp"
android:maxEms="23"
android:maxLines="2"
android:scrollHorizontally="false"
android:singleLine="false"
android:text="The Complete Banking\nCourses"
android:textColor="#color/colorPrimaryBlack"
android:textSize="18dp" />
</RelativeLayout>
or to set the TextView alignment to the ImageView like this
<ImageView
android:id="#+id/proimg"
android:layout_width="200dp"
android:layout_height="160dp"
android:background="#drawable/categoriesicon"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/txtcom"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="#id/proimg"
android:layout_marginLeft="5dp"
android:maxEms="23"
android:maxLines="2"
android:scrollHorizontally="false"
android:singleLine="false"
android:text="The Complete Banking\nCourses"
android:textColor="#color/colorPrimaryBlack"
android:textSize="18dp" />
third one will be like this
<TextView
android:id="#+id/txtcom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/proimg"
android:align_right="#id/proimg"
android:align_left="#id/proimg"
android:scrollHorizontally="false"
android:singleLine="false"
android:text="The Complete Banking\nCourses"
android:textColor="#color/colorPrimaryBlack"
android:textSize="18dp" />
I want to align the drawable and hint at center in EditText. For that I am having this piece of code,
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/relative_layout"
android:layout_margin="5dp" >
<EditText
android:id="#+id/edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Hint"
android:background="#null"
android:gravity="center"
android:textColor="#android:color/black"
android:textColorHint="#color/black"
android:textSize="14sp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:drawableLeft="#android:drawable/icon"
android:drawableStart="#android:drawable/icon" />
</RelativeLayout>
Now as soon as user starts typing, the drawable should move to extreme left of EditText. How to achieve this?
Use android:layout_gravity="center" for your EditText. This will help you setting hint in center.
and for drawable this is hack. Set your drawableTop for editText and give some paddingTop to the view.
My EditText hint seems to be misaligned with actual EditText. The problem is when I try to resize it to be smaller or larger, the hint stays in the same position but only the size of the box changes. I have an image to show how it should look because I have a Button that has its text aligned like so:
As you can see, the hint floats sightly above the bottom of the end of the EditText box. If I try todecrease the size of the EditText, the placeholder stays in the same position but the size of the box, if decreased, simply covers the hint and the hint never moves. If anything, I would want the text to be aligned to the send Button if possible.
Here is my code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/layout_comments">
<LinearLayout
android:id="#+id/send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<com.cengalabs.flatui.views.FlatEditText
android:fontFamily="sans-serif"
android:id="#+id/write_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:paddingLeft="10dp"
android:gravity="bottom|left"
android:textSize="16sp"
android:cursorVisible="false"
android:hint="Comment back!"
android:inputType="textMultiLine"
flatui:fl_fieldStyle="fl_box"
android:scrollHorizontally="false" />
<com.cengalabs.flatui.views.FlatButton
android:fontFamily="sans-serif"
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
flatui:theme="#array/sea"
flatui:fl_textAppearance="fl_light"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:scrollbars="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/send_message"
android:id="#+id/view_comments">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
Any help would be appreciated, thanks!
Change this
android:paddingLeft="10dp"
to
android:padding="10dp"
I'm trying to create a layout for a callout bubble that includes an image on the left, another image on the right and then a layout in the middle which includes a couple of TextViews.
If the length of either TextView is short enough, I want the whole callout to only be wide enough to show the text; if it's too long I want it trimmed with a '...'.
Here's a sample of the XML I'm dealing with (I've stripped out all the margins and padding etc. for clarity):
<RelativeLayout android:id="#+id/callout"
android:layout_width="wrap_content"
android:layout_height="54dp">
<ImageView android:id="#+id/callout_img_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RelativeLayout android:id="#+id/callout_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/callout_img_left">
<TextView android:id="#+id/callout_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true" />
<TextView android:id="#+id/callout_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:layout_below="#id/callout_name" />
</RelativeLayout>
<ImageView android:id="#+id/callout_img_right"
android:layout_width="48dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/callout_info"/>
</RelativeLayout>
Originally I had the image on the right using android:layout_alignParentRight="true" but this made the whole callout fill it's available width. The XML shown above works for short text, but if the text is too long it pushes out (shrinks?) the image on the right.
Perhaps a nested LinearLayout with a zero width will do the trick:
<LinearLayout android:id="#+id/callout"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="54dp">
<ImageView android:id="#+id/callout_img_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<TextView android:id="#+id/callout_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true" />
<TextView android:id="#+id/callout_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true" />
</LinearLayout>
<ImageView android:id="#+id/callout_img_right"
android:layout_width="48dp"
android:layout_height="wrap_content" />
</LinearLayout>
If you don't mind the two text views always having the same width, you can dispense with the nested LinearLayout and just give each TextView a width of 0dp and weight of 1.