I have a switch and i need the text within the switch(Eg: ON/OFF) to be ellipsized if long.
How can it be done?The following does not work!!
<Switch
android:id="#+id/switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_centerVertical="true"
android:paddingBottom="5dp"
android:layout_alignParentRight="true"
android:minWidth="80dp"
android:minHeight="18dp"
android:textOff="#string/toggle_off"
android:textOn="#string/toggle_on"
android:ellipsize:end
android:maxWidth="50dp"
android:singleLine="true"
>
</Switch>
Add this code in your java file:
Switch switch = (Switch) vi.findViewById(R.id.switch);
switch.setEllipsize(TextUtils.TruncateAt.END);
switch.setSingleLine(true);
Related
This is a part of activity (RelativeLayout):
<TextView
android:layout_marginTop="30dp"
android:layout_below="#id/tvMerchantAddress"
android:id="#+id/tvWhen"
android:textSize="12sp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text = "When you to come?" />
<DatePicker
android:layout_centerHorizontal="true"
android:id="#+id/datePicker"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:scaleX="0.75"
android:scaleY="0.75"
android:layout_marginLeft="20dp"
android:layout_marginTop="-30dp"
android:layout_marginRight="-50dp"
android:layout_marginBottom="-30dp"
android:calendarViewShown="false"
android:layout_below="#id/tvWhen"
android:datePickerMode="spinner"
android:spinnersShown="true" />
<TimePicker
android:id="#+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/datePicker"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="-30dp"
android:layout_marginRight="-50dp"
android:layout_marginBottom="-30dp"
android:scaleX="0.75"
android:scaleY="0.75"
android:timePickerMode="spinner" />
What I want to have is a DatePicker and a TimePicker on the center of the parent, which sizes are smalles then their default ones.
And this is the result:
Yes, both DatePicker and TimePicker are smaller, but leaves much unused margins. And also overlaps each other. Is there any way to do this?
I don't know how to explain my problem but below on image is what I need to do:
On image I have 4 textview in a linear layout.
I want a long text to be wrapped and to go to the new line at bottom to another textView.
how could I have 4 textView like on that image ?
Thanks.
Add dependency to your gradle file:
dependencies {
implementation 'com.google.android:flexbox:2.0.1'
}
and add this to your xml file:
<com.google.android.flexbox.FlexboxLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:alignContent="flex_start"
app:alignItems="flex_start"
app:flexWrap="wrap"
app:showDivider="beginning|middle"
app:dividerDrawable="#drawable/divider" >
<TextView
style="#style/FlexItem"
android:layout_width="220dp"
android:layout_height="80dp"
android:text="1" />
<TextView
style="#style/FlexItem"
android:layout_width="120dp"
android:layout_height="80dp"
android:text="2" />
<TextView
style="#style/FlexItem"
android:layout_width="160dp"
android:layout_height="80dp"
android:text="3" />
<TextView
style="#style/FlexItem"
android:layout_width="80dp"
android:layout_height="80dp"
android:text="4" />
<TextView
style="#style/FlexItem"
android:layout_width="100dp"
android:layout_height="80dp"
android:text="5" />
After many days of search; I did not find anything.
It is not possible to align TextViews like that.
The solutions is using the SpannableString.
No matter what I do my EditText appears like this :
My XML :
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout_search"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_gravity="top"
android:gravity="top"
android:layout_height="wrap_content">
<EditText
android:background="#null"
android:textColor="#color/black"
android:layout_centerInParent="true"
android:gravity="top"
android:layout_gravity="top"
android:id="#+id/SearchText"
android:textColorLink="#color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#color/normatext"
android:inputType="text"/>
</android.support.design.widget.TextInputLayout>
I changed all possible values for gravity and layout_gravity in every possible variation! Any ideas ?
EDIT :
Full Layout :
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginTop="0dp"
android:paddingTop="6dp"
android:paddingBottom="5dp"
android:layout_margin="3dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="45dp">
<Button
android:layout_width="43dp"
android:layout_height="wrap_content"
android:background="#drawable/ham"
android:id="#+id/hambtn"
android:textColorHint="#color/black"
android:layout_weight="0"
/>
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout_search"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_gravity="top"
android:gravity="top"
android:layout_height="wrap_content">
<EditText
android:background="#null"
android:textColor="#color/black"
android:layout_centerInParent="true"
android:gravity="top"
android:layout_gravity="top"
android:id="#+id/SearchText"
android:textColorLink="#color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#color/normatext"
android:inputType="text"/>
</android.support.design.widget.TextInputLayout>
<Button
android:layout_width="55dp"
android:layout_weight="0"
android:layout_height="match_parent"
android:background="#drawable/my_button_bg"
android:text="news"
android:id="#+id/newsbtn"
android:layout_marginLeft="8dp"
android:layout_marginRight="6dp"
android:paddingBottom="5dp"
/>
</LinearLayout>
I think the problem is maybe in your topmost LinearLayout view.
Try removing those lines:
android:layout_marginTop="0dp"
android:paddingTop="6dp"
android:paddingBottom="5dp"
android:layout_margin="3dp"
and add those lines instead to make sure there are no padding and margin at all:
android:padding="0dp"
android:layout_margin="0dp"
If it did solve the problem, you can go ahead and read more about padding and margin here.
If not, I would suspect that your TextInputLayout gets confused because of the inner EditText asking it to be both top and center. remove the "center" part (e.g. remove this - android:layout_centerInParent="true" from your EditText) and check if it solves your issue :)
Never had this problem before but i would make sure explicitly that there is no padding in the parent and no margin in the child. i.e.:
<android.support.design.widget.TextInputLayout
...
android:padding="0dp"
>
<EditText
...
android:layout_margin="0dp"
/>
</android.support.design.widget.TextInputLayout>
Can You remove the background tag of EditText and reply me if it works or not ?
Also provide your full layout file for exact solution.
I have a linear layout, with layout parameters of fill parent, and wrap content. The orientation is horizontal.
Inside the linear layout I have two buttons. They appear next to each other on the left hand side.
I would like the two buttons to "fully justify". In other words I want each button to take half the width of the linear layout.
Can anybody help?
use weights like:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:text="Button1"
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:text="Button2"
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
define a weight sum for the parent set each children to half
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:text="Button1"
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:text="Button2"
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
I placed a TextView and a Spinner inside a TableRow but I cannot change the width of the Spinner. When I put it in RelativeLayout everything works fine, I can set custom width, wrap_content or match_parent but when I put it in TableRow no matter what I do it has a constant width. Can anybody tell me how can I make it to match_parent in TableRow?
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/logo" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/text"
android:textSize="18sp" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:drawSelectorOnTop="true"
android:entries="#array/items"
android:prompt="#string/prompt"
android:textSize="18sp" />
</TableRow>
</TableLayout>
For the spinner:
android:layout_weight="1"
This helped me.