Dynamically set height of an EditText based on the content
I have an Edit text in which i am using setText to load the data on an edit form. Currently the editText height is fixed and if the text Is larger than the editText height i can't see the full text at once.
Is there a way based on the content i can dynamically set the height of an EditText.
Thanks in advance for your help and suggestions
Regards
R
add a comment |
I have an Edit text in which i am using setText to load the data on an edit form. Currently the editText height is fixed and if the text Is larger than the editText height i can't see the full text at once.
Is there a way based on the content i can dynamically set the height of an EditText.
Thanks in advance for your help and suggestions
Regards
R
1
show me your xml code for edittext
– Ramesh Kumar
Oct 14 '17 at 6:39
add a comment |
I have an Edit text in which i am using setText to load the data on an edit form. Currently the editText height is fixed and if the text Is larger than the editText height i can't see the full text at once.
Is there a way based on the content i can dynamically set the height of an EditText.
Thanks in advance for your help and suggestions
Regards
R
I have an Edit text in which i am using setText to load the data on an edit form. Currently the editText height is fixed and if the text Is larger than the editText height i can't see the full text at once.
Is there a way based on the content i can dynamically set the height of an EditText.
Thanks in advance for your help and suggestions
Regards
R
asked Oct 14 '17 at 6:33
BRDroidBRDroid
69421333
69421333
1
show me your xml code for edittext
– Ramesh Kumar
Oct 14 '17 at 6:39
add a comment |
1
show me your xml code for edittext
– Ramesh Kumar
Oct 14 '17 at 6:39
1
1
show me your xml code for edittext
– Ramesh Kumar
Oct 14 '17 at 6:39
show me your xml code for edittext
– Ramesh Kumar
Oct 14 '17 at 6:39
add a comment |
5 Answers
5
active
oldest
votes
try setting the height of edit text as following :
android:layout_height="wrap_content"
add a comment |
You can use this code for your xml file:
<EditText
android:id="@+id/edtFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/first_name"
android:padding="5dp"
android:textColor="@color/black"
android:textSize="16sp" />
while your edit text contain comes it automatically fit the text size.
Do not use android:singleLine="true" or android:minLines="1" and android:maxLines="1"
add a comment |
Set android:layout_height wrap_content is best Approach .
The view should be only big enough to enclose its content .
Use DisplayMetrics for Dynamically set the height of an EditText.
DisplayMetrics metrics = getResources().getDisplayMetrics();
int DeviceTotalWidth = metrics.widthPixels;
int DeviceTotalHeight = metrics.heightPixels;
How ?
if(length()>n) // n is your String length
editTEXT.getLayoutParams().height=DeviceTotalHeight*10/100;
add a comment |
Try, this one may help -:
edittext.getLayoutParams().width=50
et= (CustomEditText) findViewById(R.id.et);
ViewGroup.LayoutParams lp = et.getLayoutParams();
lp.width = 100;
lp.height = 100;
et.setLayoutParams(lp);
add a comment |
This may help you,
Using android:layout_height ="wrap_content" and android:inputType="textMultiLine" are best approach
<EditText
android:id ="@+id/editText"
android:layout_width ="match_parent"
android:layout_height ="wrap_content"
android:inputType="textMultiLine"
android:hint ="Hint"
android:scrollHorizontally="false" />
I will suggest you to use ScrollView as a parent layout of EditText
It prevents your EditText to cut off (outside from the screen) from screen when you have a larger text
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46741626%2fdynamically-set-height-of-an-edittext-based-on-the-content%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
try setting the height of edit text as following :
android:layout_height="wrap_content"
add a comment |
try setting the height of edit text as following :
android:layout_height="wrap_content"
add a comment |
try setting the height of edit text as following :
android:layout_height="wrap_content"
try setting the height of edit text as following :
android:layout_height="wrap_content"
answered Oct 14 '17 at 6:40
Akhilesh AwasthiAkhilesh Awasthi
1,67231223
1,67231223
add a comment |
add a comment |
You can use this code for your xml file:
<EditText
android:id="@+id/edtFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/first_name"
android:padding="5dp"
android:textColor="@color/black"
android:textSize="16sp" />
while your edit text contain comes it automatically fit the text size.
Do not use android:singleLine="true" or android:minLines="1" and android:maxLines="1"
add a comment |
You can use this code for your xml file:
<EditText
android:id="@+id/edtFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/first_name"
android:padding="5dp"
android:textColor="@color/black"
android:textSize="16sp" />
while your edit text contain comes it automatically fit the text size.
Do not use android:singleLine="true" or android:minLines="1" and android:maxLines="1"
add a comment |
You can use this code for your xml file:
<EditText
android:id="@+id/edtFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/first_name"
android:padding="5dp"
android:textColor="@color/black"
android:textSize="16sp" />
while your edit text contain comes it automatically fit the text size.
Do not use android:singleLine="true" or android:minLines="1" and android:maxLines="1"
You can use this code for your xml file:
<EditText
android:id="@+id/edtFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/first_name"
android:padding="5dp"
android:textColor="@color/black"
android:textSize="16sp" />
while your edit text contain comes it automatically fit the text size.
Do not use android:singleLine="true" or android:minLines="1" and android:maxLines="1"
edited Nov 20 '18 at 6:21
answered Oct 14 '17 at 6:53
Ramesh KumarRamesh Kumar
9641323
9641323
add a comment |
add a comment |
Set android:layout_height wrap_content is best Approach .
The view should be only big enough to enclose its content .
Use DisplayMetrics for Dynamically set the height of an EditText.
DisplayMetrics metrics = getResources().getDisplayMetrics();
int DeviceTotalWidth = metrics.widthPixels;
int DeviceTotalHeight = metrics.heightPixels;
How ?
if(length()>n) // n is your String length
editTEXT.getLayoutParams().height=DeviceTotalHeight*10/100;
add a comment |
Set android:layout_height wrap_content is best Approach .
The view should be only big enough to enclose its content .
Use DisplayMetrics for Dynamically set the height of an EditText.
DisplayMetrics metrics = getResources().getDisplayMetrics();
int DeviceTotalWidth = metrics.widthPixels;
int DeviceTotalHeight = metrics.heightPixels;
How ?
if(length()>n) // n is your String length
editTEXT.getLayoutParams().height=DeviceTotalHeight*10/100;
add a comment |
Set android:layout_height wrap_content is best Approach .
The view should be only big enough to enclose its content .
Use DisplayMetrics for Dynamically set the height of an EditText.
DisplayMetrics metrics = getResources().getDisplayMetrics();
int DeviceTotalWidth = metrics.widthPixels;
int DeviceTotalHeight = metrics.heightPixels;
How ?
if(length()>n) // n is your String length
editTEXT.getLayoutParams().height=DeviceTotalHeight*10/100;
Set android:layout_height wrap_content is best Approach .
The view should be only big enough to enclose its content .
Use DisplayMetrics for Dynamically set the height of an EditText.
DisplayMetrics metrics = getResources().getDisplayMetrics();
int DeviceTotalWidth = metrics.widthPixels;
int DeviceTotalHeight = metrics.heightPixels;
How ?
if(length()>n) // n is your String length
editTEXT.getLayoutParams().height=DeviceTotalHeight*10/100;
edited Oct 14 '17 at 7:00
answered Oct 14 '17 at 6:53
IntelliJ AmiyaIntelliJ Amiya
53.3k12112134
53.3k12112134
add a comment |
add a comment |
Try, this one may help -:
edittext.getLayoutParams().width=50
et= (CustomEditText) findViewById(R.id.et);
ViewGroup.LayoutParams lp = et.getLayoutParams();
lp.width = 100;
lp.height = 100;
et.setLayoutParams(lp);
add a comment |
Try, this one may help -:
edittext.getLayoutParams().width=50
et= (CustomEditText) findViewById(R.id.et);
ViewGroup.LayoutParams lp = et.getLayoutParams();
lp.width = 100;
lp.height = 100;
et.setLayoutParams(lp);
add a comment |
Try, this one may help -:
edittext.getLayoutParams().width=50
et= (CustomEditText) findViewById(R.id.et);
ViewGroup.LayoutParams lp = et.getLayoutParams();
lp.width = 100;
lp.height = 100;
et.setLayoutParams(lp);
Try, this one may help -:
edittext.getLayoutParams().width=50
et= (CustomEditText) findViewById(R.id.et);
ViewGroup.LayoutParams lp = et.getLayoutParams();
lp.width = 100;
lp.height = 100;
et.setLayoutParams(lp);
edited Oct 14 '17 at 6:46
UltimateDevil
2,11321030
2,11321030
answered Oct 14 '17 at 6:43
mehulmehul
1,185416
1,185416
add a comment |
add a comment |
This may help you,
Using android:layout_height ="wrap_content" and android:inputType="textMultiLine" are best approach
<EditText
android:id ="@+id/editText"
android:layout_width ="match_parent"
android:layout_height ="wrap_content"
android:inputType="textMultiLine"
android:hint ="Hint"
android:scrollHorizontally="false" />
I will suggest you to use ScrollView as a parent layout of EditText
It prevents your EditText to cut off (outside from the screen) from screen when you have a larger text
add a comment |
This may help you,
Using android:layout_height ="wrap_content" and android:inputType="textMultiLine" are best approach
<EditText
android:id ="@+id/editText"
android:layout_width ="match_parent"
android:layout_height ="wrap_content"
android:inputType="textMultiLine"
android:hint ="Hint"
android:scrollHorizontally="false" />
I will suggest you to use ScrollView as a parent layout of EditText
It prevents your EditText to cut off (outside from the screen) from screen when you have a larger text
add a comment |
This may help you,
Using android:layout_height ="wrap_content" and android:inputType="textMultiLine" are best approach
<EditText
android:id ="@+id/editText"
android:layout_width ="match_parent"
android:layout_height ="wrap_content"
android:inputType="textMultiLine"
android:hint ="Hint"
android:scrollHorizontally="false" />
I will suggest you to use ScrollView as a parent layout of EditText
It prevents your EditText to cut off (outside from the screen) from screen when you have a larger text
This may help you,
Using android:layout_height ="wrap_content" and android:inputType="textMultiLine" are best approach
<EditText
android:id ="@+id/editText"
android:layout_width ="match_parent"
android:layout_height ="wrap_content"
android:inputType="textMultiLine"
android:hint ="Hint"
android:scrollHorizontally="false" />
I will suggest you to use ScrollView as a parent layout of EditText
It prevents your EditText to cut off (outside from the screen) from screen when you have a larger text
edited Oct 14 '17 at 7:23
answered Oct 14 '17 at 7:02
UltimateDevilUltimateDevil
2,11321030
2,11321030
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f46741626%2fdynamically-set-height-of-an-edittext-based-on-the-content%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
show me your xml code for edittext
– Ramesh Kumar
Oct 14 '17 at 6:39