Does anybody know why my table row height increases when I remove the background property of containing EditText?
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1,3" >
<TableRow
android:id="#+id/tr3a"
android:padding="2.5dp"
android:background="#color/col1"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="#+id/lab_bookname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/bookname" />
<EditText
android:id="#+id/bookname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_span="3"
android:textSize="14sp"
android:background="#color/white" // FOR VIEW 1, I REMOVE THIS LINE, NO OTHER CHANGE
android:hint="#string/definputtext2" />
</TableRow>
Height changes because by setting a custom background you are replacing the EditText default background, which might not be just a color resource.
Check these similar questions:
Problem with EditText background (android)
EditText dimensions change if I use color as a background?
Related
I'm facing problems with the position of an icon. I've set that icon as drawableLeft of a TextView, this is working fine but, if I set the TextView's gravity to center_horizontal, then a padding space appears between the icon and the text. The code is as follows:
<TextView
style="#style/BaseText.White.Bold"
android:gravity="center_horizontal"
android:drawableStart="#drawable/ic_text"
android:drawableLeft="#drawable/ic_text"
android:text="#string/text"
android:layout_marginBottom="#dimen/margin_small"
android:layout_marginRight="#dimen/margin_big"
android:layout_marginLeft="#dimen/margin_big"
android:padding="0dp"
android:drawablePadding="0dp"/>
What do I have to do to ensure that the icon is shown at the text's left side but horizontally centered?
I've make two screenshots to show you the difference when adding or removing the icon's gravity.
When the textview's gravity is not set, the result is as follows:
But, when the gravity is added, then a padding appears between the text and the icon:
Thanks in advance
Only add android:drawablePadding="10dp" field in your text view refer the coad
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add New Address"
android:textAppearance="#style/Title"
android:id="#+id/tvAddNewAddress"
android:drawablePadding="20dp"
android:layout_weight="1"
android:padding="5dp"
android:textColor="#color/colorAccent"
android:drawableStart="#android:drawable/arrow_down_float"
/>
Try to give android:gravity="center" to Text View. Also add android:layout_width="wrap_content" and android:layout_height="wrap_content" properties in Text View.
Refer this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:drawableLeft="#mipmap/ic_launcher"
android:drawablePadding="0dp"
android:drawableStart="#mipmap/ic_launcher"
android:gravity="center"
android:textSize="22sp"
android:padding="0dp"
android:text="TestingTestingTestingTestingTestingTestingTestingTestingTesting" />
</RelativeLayout>
This is what it showing.
I'm working on an app where my xml looks a bit like this:
<TableRow
android:layout_width="match_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/receiver_name"
android:layout_weight="1" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:maxLength="30"
android:maxLines="1" />
</TableRow>
What I want, is that no matter what device you have, the TextView should take up 1/4th of the width, and the EditText should take up 3/4ths of the width.
As it is now, the code works - until you start typing. The EditText gets wider and wider as you type more and more into it. How do I make it so that my EditText stays the same width that is assigned to it by the layout_weight parameters?
you should use LinearLayout like that :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/receiver_name"
android:layout_weight="1" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:maxLength="30"
android:maxLines="1" />
</LinearLayout>
hope that can help you =)
Just like Janoub said you could use the LinearLayout and weights value.
http://developer.android.com/guide/topics/ui/layout/linear.html
But you can also use table layout with 4 columns so your edittext catches 3 columns and the textview 1.
http://www.compiletimeerror.com/2013/07/android-tablelayout-example.html
I'm creating one table layout with text view and spinner.
My textview content is too large, so it's wrapped up in my layout. Whenever the textview having wrapped, the same row spinner also increased the height.
My code is,
<TableRow
android:id="#+id/trConfigPeriodStop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:weightSum="1" >
<TextView
android:id="#+id/tvConfigPeriodStop"
android:text="Periodic reporting interval while moving"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:textColor="#color/gpsblue"
android:layout_marginLeft="5dp" />
<Spinner
android:id="#+id/spnConfigPeriodStop"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:entries="#array/periodstop_arrays"
android:prompt="#string/periodstop_prompt"
/>
</TableRow>
Suppose I'm changing the layout height in wrap_content in spinner, that time my text view text also hide from view.
How to solve this issue?
Please do the needful.
Thanks in advance.
Try setting layout height as wrap_content for both Spinner and TextView.
Try this :
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/trConfigPeriodStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textColor="#color/gpsblue"
android:weightSum="1" >
<TextView
android:id="#+id/tvConfigPeriodStop"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_weight="0.5"
android:text="Periodic reporting interval while moving" />
<Spinner
android:id="#+id/spnConfigPeriodStop"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:entries="#array/periodstop_arrays"
android:prompt="#string/periodstop_prompt" />
</TableRow>
i guess it is because tablerow has android:layout_height="wrap_content" and inner textview has android:layout_height="fill_parent", so the height of the tablerow will fit to the height of the spinner, that is the only child with fixed and independent height while rendering.
you will solve it if you change TextView's height also to android:layout_height="wrap_content"
How would I make the TextView_height=content_height+padding
When I am adding some top-padding to the textbox - it moves the content behind the borders of the TextView.
This is right, since I made the TextView to be as tall as the content.
Is it possible to make the TextView as tall as content + padding?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
tools:context=".DisplayActivity" >
<TextView
android:id="#+id/TopmessageStripe"
style="#style/TopmessageStripeTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="false"
android:layout_centerHorizontal="true"
android:height="#dimen/big_margin"
android:paddingTop="5dp"
android:text="TextView" />
</RelativeLayout>
This is most likely your problem
android:height="#dimen/big_margin"
It is setting a custom height instead of wrapping the content.
Not sure how to do it using the gui but this might be what you're looking for in the xml for the text view
<TextView
android:id="#+id/mTextView"
android:paddingTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</TextView>
I am aiming for a layout similar to the native calculator app. I want text to trail off the left of the screen without moving the buttons on the right. Currently my text moves to the left until filling the screen at which point the buttons are pushed off the right edge.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_weight="1"
android:gravity="right"
android:orientation="horizontal" >
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none" >
<TextView
android:id="#+id/display_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#android:color/white"
android:textIsSelectable="true"
android:textSize="30sp" />
</HorizontalScrollView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/delete_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onDelete"
android:text="#string/delete_button" />
<Button
android:id="#+id/equate_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onEquate"
android:text="#string/equate_button" />
</LinearLayout>
</LinearLayout>
You don't need to put your TextView into a HorizontalScrollView, it will automatically become scrollable when the text exceeds the bounds. See docs: http://developer.android.com/reference/android/widget/TextView.html#attr_android:scrollHorizontally
Just add android:scrollHorizontally="true" to the TextView in the layout.
You may also need to change the text view's layout_weight to 0 or set its layout_width to something fixed (like 100dp).
To get the text to go right-to-left, set the gravity on the TextView to be android:gravity="right|center_vertical"
I also humbly refer you the source of the calculator app you are trying to emulate: https://github.com/android/platform_packages_apps_calculator/tree/master/src