edittext does not grow downwards, text goes out of the visible area - android

Problem :- In case i have more than 1 line in my edittext, the previous line goes out of the visible area. I was expecting it to grow downwards so that all lines are visible.
Xml for my compound control which has this edittext:-
<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:id="#+id/composite_control_layout"
android:background="#null"
tools:context="com.gp.app.professionalpa.layout.ListItemLayout" >
<Button android:id="#+id/compositeControlAddItem"
android:layout_height="30dip"
android:layout_width="30dip"
android:text="#string/plus"/>
<ImageView
android:id="#+id/compositeControlImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"
android:contentDescription="#string/note_image"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:layout_toRightOf="#id/compositeControlAddItem"
android:layout_alignBottom="#id/compositeControlAddItem"
android:layout_alignParentLeft="true"
android:visibility="invisible"/>
<!-- <ImageButton
android:id="#+id/compositeControlBulletButton"
android:layout_width="35dip"
android:layout_height="#dimen/composite_control_height"
android:layout_marginRight="2dip"
android:contentDescription="#string/set_importance"
android:src="#drawable/ic_pin_black_bullet_point" /> -->
<EditText
android:id="#+id/compositeControlTextBox"
android:layout_width="250dip"
android:layout_height="#dimen/composite_control_height"
android:background="#null"
android:hint="#string/add_note"
android:layout_marginLeft="2dip"
android:layout_toRightOf="#+id/compositeControlAddItem"
android:layout_alignBottom="#+id/compositeControlAddItem"
android:inputType="textAutoCorrect|textMultiLine|textAutoComplete|textCapSentences"
android:maxLines="7"
android:maxLength="200"/>
<Button android:id="#+id/compositeControlDeleteItem"
android:layout_height="30dip"
android:layout_width="30dip"
android:layout_toRightOf="#+id/compositeControlTextBox"
android:layout_alignBottom="#+id/compositeControlTextBox"
android:text="#string/minus"/>
</RelativeLayout>
In my activity i am creating this compound contrl using the following code:-
private void addNewListItem()
{
ListViewItemLayout currentAddedListItem = new ListViewItemLayout(this);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.alignWithParent = true;
if(lastAddedListItem != null)
{
layoutParams.addRule(RelativeLayout.BELOW, lastAddedListItem.getId());
}
currentAddedListItem.setLayoutParams(layoutParams);
activityLayout.addView(currentAddedListItem, listItems.size());
listItems.add(currentAddedListItem);
Button button = currentAddedListItem.getAddButton();
lastAddedListItem = currentAddedListItem;
}
Image showing that the previous lines becomes invisible in case edittext enters new line:-

Try editing the layout height of your edit text ... prob looks with your composite height used

strong textjust use android:paddingEnd = "your "

Related

Characters appear in the order as i click

For example. There is picture on the top of the screen below that there are some empty boxes and below the boxes there are some buttons. Every button has a character for text("a","c","t"). You click on a button and the button's text appear in the box. You can click them in the order you want to but the answer is "cat" so when you put the characters in the correct order then you got a toast.
I tried to do it with TextViews and Buttons. I can make the button disappear when i click on it and a textview appear in the same time. But every textview has a fix place on the screen, so i need to put every character in every box invisible and when i click on the "c" character it appear in the first box and the other "c" characters stay invisible. But if i click on the "a" first, then it appears in the second box because there is too much variation to do all. I'm not good at explaining but if anyone has an idea how to do that easier please response!
Here is my code:
public class MainActivity extends ActionBarActivity implements OnClickListener{
Button b1;
Button b2;
Button b3;
TextView tg1;
TextView tg2;
TextView tg3;
TextView to1;
TextView to2;
TextView to3;
TextView tl1;
TextView tl2;
TextView tl3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button)findViewById(R.id.bg);
b1.setOnClickListener(this);
b2 = (Button)findViewById(R.id.bo);
b2.setOnClickListener(this);
b3 = (Button)findViewById(R.id.bl);
b3.setOnClickListener(this);
tg1 = (TextView)findViewById(R.id.tg1);
tg2 = (TextView)findViewById(R.id.tg2);
tg3 = (TextView)findViewById(R.id.tg3);
to1 = (TextView)findViewById(R.id.to1);
to2 = (TextView)findViewById(R.id.to2);
to3 = (TextView)findViewById(R.id.to3);
tl1 = (TextView)findViewById(R.id.tl1);
tl2 = (TextView)findViewById(R.id.tl2);
tl3 = (TextView)findViewById(R.id.tl3);
}
#Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.bg:
b1.setVisibility(View.INVISIBLE);
tg1.setVisibility(View.VISIBLE);
tg2.setVisibility(View.INVISIBLE);
tg3.setVisibility(View.INVISIBLE);
break;
case R.id.bo:
b2.setVisibility(View.INVISIBLE);
to2.setVisibility(View.VISIBLE);
to1.setVisibility(View.INVISIBLE);
to3.setVisibility(View.INVISIBLE);
break;
case R.id.bl:
b3.setVisibility(View.INVISIBLE);
tl3.setVisibility(View.VISIBLE);
tl2.setVisibility(View.INVISIBLE);
tl1.setVisibility(View.INVISIBLE);
}
}
}
<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="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="hu.szada.gombokelso.MainActivity"
android:orientation="horizontal">
<TextView
android:id="#+id/tl1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="invisible"
android:text="l"/>
<Button
android:id="#+id/bo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="86dp"
android:onClick="onClick"
android:text="o" />
<Button
android:id="#+id/bl"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/bg"
android:layout_alignBottom="#+id/bg"
android:layout_alignParentLeft="true"
android:layout_marginLeft="36dp"
android:onClick="onClick"
android:text="l" />
<Button
android:id="#+id/bg"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginRight="14dp"
android:layout_toLeftOf="#+id/bo"
android:onClick="onClick"
android:text="g" />
<TextView
android:id="#+id/tg1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tl"
android:layout_alignBottom="#+id/tl"
android:layout_alignLeft="#+id/tl"
android:layout_weight="1"
android:visibility="invisible"
android:text="g" />
<TextView
android:id="#+id/to1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tl"
android:layout_alignBottom="#+id/tl"
android:layout_alignLeft="#+id/tl"
android:layout_weight="1"
android:visibility="invisible"
android:text="o" />
/// Second
<TextView
android:id="#+id/to2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tl1"
android:layout_alignBottom="#+id/tl1"
android:layout_marginLeft="19dp"
android:layout_toRightOf="#+id/tl1"
android:layout_weight="1"
android:visibility="invisible"
android:text="o" />
<TextView
android:id="#+id/tg2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/to2"
android:layout_alignBottom="#+id/to2"
android:layout_alignLeft="#+id/to2"
android:layout_weight="1"
android:visibility="invisible"
android:text="g" />
<TextView
android:id="#+id/tl2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/to2"
android:layout_alignBottom="#+id/to2"
android:layout_alignRight="#+id/to2"
android:layout_weight="1"
android:visibility="invisible"
android:text="l" />
/// Third
<TextView
android:id="#+id/tg3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/to2"
android:layout_alignBottom="#+id/to2"
android:layout_alignRight="#+id/bl"
android:layout_weight="1"
android:visibility="invisible"
android:text="g" />
<TextView
android:id="#+id/tl3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tg3"
android:layout_alignBottom="#+id/tg3"
android:layout_alignLeft="#+id/tg3"
android:layout_weight="1"
android:visibility="invisible"
android:text="l" />
<TextView
android:id="#+id/to3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tg3"
android:layout_alignBottom="#+id/tg3"
android:layout_toRightOf="#+id/tl3"
android:layout_weight="1"
android:visibility="invisible"
android:text="o" />
You might want to try a slightly different approach.
If I understand you correctly, you want to "type" a word out using given lettered buttons. Like one of those hangman style games.
Why not append the text views on the fly.
Something like
#Override
public void onClick(View v) {
//Grab the surrounding layout for the textviews
GridView answerGrid = (GridView)getViewById(R.id.answerGrid);
//Get the text that was on the button
Button b = (Button)v;
String btnText = b.getText().toString();
//Make a text view with text
TextView txt = new TextView();
text.setText(btnText);
//Append to text view container
answerGrid.addView(txt);
//Invisible button
b.setVisibility(View.INVISIBLE);
}
Haven't tested to see if this is perfect, but its a start.
=====
I've looked at your xml
Why not use GridViews?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
....>
<GridView android:id="#+id/answerGrid"
....>
<!-- Put nothing here. This is for answers -->
</GridView>
<GridView android:id="#+id/lettersGrid"
android:layout_below="answerGrid"
....>
<!-- Buttons in here -->
</GridView>
</RelativeLayout>
This way you can customise the number of rows/columns based on the length of the word you're playing with. And GridView will automatically give you a neat layout and spacing.
Have a look at the GridView doc and get it customised the way you want it.
See my edits above for the Java code.

how to place ImageViews into RelativeLayout programatically

I am placing several ImageViews (eggs) into RelativeLayout
a link to image
I would like to have them all the same size aligned in the row, however if there is not enough place left for all of them RelativeLayout just shrinks on of them and all the remaining ones are just omitted.
Is there any way how to tell RelativeLayout to resize them equally, so that all of them fit to the screen and have uniform size (intependent of the screen size and resolution)?
it should look like this, however with all of them included:
(https://docs.google.com/drawings/d/1H1Ij1hyxva2WVxb7HM6jNhju3VLeVn_W-mHhh3VHtJg/edit)
This is part of my code
private void testLoadEggs() {
RelativeLayout.LayoutParams params;
RelativeLayout rl = new RelativeLayout(getContext());
List<ImageView> imageEggs = new ArrayList();
for (int i = 0; i < 11; i++) {
imageEggs.add(new ImageView(getContext()));
SVG svg = SVGParser.getSVGFromResource(this.getResources(), R.raw.white_egg);
imageEggs.get(i).setImageDrawable(svg.createPictureDrawable());
params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.addRule(ALIGN_PARENT_BOTTOM);
if (i==0)
{
params.addRule(ALIGN_PARENT_LEFT);
}
else {
params.addRule(RIGHT_OF,i-1);
}
imageEggs.get(i).setId(i);
imageEggs.get(i).setVisibility(View.VISIBLE);
rl.addView(imageEggs.get(i), params);
}
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
params2.addRule(ALIGN_PARENT_BOTTOM);
params2.addRule(CENTER_HORIZONTAL);
this.addView(rl, params2);
}`
the actual call:
this.setBackgroundColor(Color.parseColor("#81D4FA"));
this.setGravity(Gravity.CENTER);
testLoadEggs();
Instead of adding your views to RelativeLayout you can add them to LinearLayout with orientation="horizontal" and with each layout set to android:layout_weight="1"
You should use Linear Layout and you can easily put your button or image with same size. For example;
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"/>
or you can use more of them and put whatever do you want;
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="100"
>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="30"/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="30"/>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="30"/>

different values in onProgressChanged() and onStopTrackingTouch in SeekBar

I'm dynamically modifying height of the button based on seekbar progress.
Now I want to retreive height of the button. So I used btn1.getHeight() in onProgressChanged() method of SeekBar.
But it gives incorrect/old set of values for button height.
Instead, if I used btn1.getHeight() in onStopTrackingTouch(), I'm getting correct values.
This simply means , when I try to retreive height of the button in onProgressChanged() , UI changes are visible on screen but yet not registered wchich results into getting incorrect/old values.
How to get correct values in onProgressChanged() ?
Is there other way round to do this? Any help appreciated.
Edit
#Luksprog : I made following changes :
<SeekBar
android:id="#+id/seekBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:maxHeight="9dp"
android:minHeight="9dp"
android:padding="10dp"
android:max="100"
android:progressDrawable="#drawable/seekbar_progress"
android:thumb="#drawable/shine_btn" />
<RelativeLayout
android:id="#+id/Graph01"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_below="#id/seekBar"
android:layout_marginTop="50dp"
android:gravity="bottom" >
<Button
android:id="#+id/btnGraph01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#99f" />
<com.example.calci.views.MyTextView
android:id="#+id/tvGraph01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/btnGraph01" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/Graph02"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_below="#id/seekBar"
android:layout_toRightOf="#id/Graph01"
android:layout_marginTop="50dp"
android:gravity="bottom" >
<Button
android:id="#+id/btnGraph02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#99f" />
<com.example.calci.views.MyTextView
android:id="#+id/tvGraph02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/btnGraph02" />
</RelativeLayout>
</RelativeLayout>
and in activity
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(20,
2 * progress * 1);
lp2.setMargins(55, 0, 0, 0);
btnGraph01.setLayoutParams(lp2);
RelativeLayout.LayoutParams lp3 = new RelativeLayout.LayoutParams(
new ViewGroup.MarginLayoutParams(20,
RelativeLayout.LayoutParams.WRAP_CONTENT));
lp3.setMargins(55, 0, 0, 30);
tvGraph01.setLayoutParams(lp3);
tvGraph01.setTextSize(6);
tvGraph01.setGravity(Gravity.CENTER);
But TextView is getting displayed inside button... Why it is so?
PLEASE CORRECT ME IF I"M WRONG...
First I'm guessing this is related to your previous question. I wouldn't use weights, instead I would simply use a RelativeLayout with the Buttons attached to the bottom, this way the Buttons will increase in height upwards. Like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/parent" >
<SeekBar
android:id="#+id/sb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:max="200"/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#99cc00"
android:text="Button"
android:onClick="test" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/button1"
android:background="#0077cc"
android:text="Button" />
</RelativeLayout>
Second, I don't see why you can't get the desired height. With my code above by using button.getHeight() you'll get the previous height store(as the new height will not be stored until you get out of onProgressChanged). But this shouldn't stop you from getting the new height because you are actually calculating that value yourself with :
progress * 10
Code:
#Override
public void onProgressChanged(SeekBar seekBar, final int progress,
boolean fromUser) {
LayoutParams lp = findViewById(R.id.button1).getLayoutParams();
lp.width = 50;
lp.height = progress * 10;
findViewById(R.id.button1).setLayoutParams(lp);
Log.e("XZX", "Progress : " + progress + " |Old height : "
+ findViewById(R.id.button1).getHeight()
+ " |New height : " + (progress * 10));
}
Edit:
Your layout file is wrong:
<RelativeLayout
android:id="#+id/Graph01"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_below="#id/seekBar"
android:layout_marginTop="50dp" >
<Button
android:id="#+id/btnGraph01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#99f" />
<com.example.calci.views.MyTextView
android:id="#+id/tvGraph01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/btnGraph01" />
</RelativeLayout>
Now in code there is no need to modify the LayoutParams of tvGraph01, it will follow the Button as it grows/shrinks, also get the current LayoutParams of the Button and modify it instead of creating new ones again and again:
RelativeLayout.LayoutParams lp2 = (RelativeLayout.LayoutParams)btnGraph01.getLayoutParams();
lp2.width = 20;
lp2.height = 2 * progress * 1;
lp2.setMargins(55, 0, 0, 0); // <= do you really need the margin? what is its purpose?
btnGraph01.setLayoutParams(lp2);
tvGraph01.setTextSize(6);

Dynamically add edit text to a layout

I am trying to add an edit text view dynamically to a layout from the java class. However from what I have implemented nothing changes on my action. This is what I have:
public final void onCreate(final Bundle i){
int value = 0;
isEdit = false;
try
{
super.onCreate(i);
this.setContentView(R.layout.contactedit);
ContactList.soundIndicator = 0;
etPhoneNumber = new ArrayList<EditText>();
this.etPhoneNumber.add((EditText) this.findViewById(R.id.etPhoneNumberInput));
this.addNumberBtn = (Button) this.findViewById(R.id.addNumberEditText);
addNumberBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//etPhoneNumber.add(new EditText(ContactEdit.this));
try{
LinearLayout layout = (LinearLayout) findViewById(R.id.contacteditll);
EditText temp = new EditText(ContactEdit.this);
temp.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
etPhoneNumber.add(temp);
layout.addView(temp);
}catch(Exception e){
Log.d(TAG, "Failed to create new edit text");
}
}
});
}
This is the xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:orientation="vertical"
android:id="#+id/contacteditll"
android:background="#drawable/darkimg">
<TextView
android:id="#+id/titlePrint"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/titlePrompt"
/>
<Spinner
android:id="#+id/spContactTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/titlePrompt"
/>
<TextView
android:text="#string/namePrint"
android:id="#+id/namePrint"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:layout_width="match_parent"
android:hint="#string/returnName"
android:id="#+id/etFirstNameInput"
android:layout_height="wrap_content"
android:layout_toRightOf= "#+id/namePrint">
</EditText>
<TextView
android:text="#string/secondPrint"
android:id="#+id/secondPrint"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:layout_width="match_parent"
android:hint="#string/returnName"
android:id="#+id/etSecondNameInput"
android:layout_height="wrap_content"
android:layout_toRightOf= "#+id/namePrint">
</EditText>
<TextView android:id="#+id/numberPrint"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/numberPrint">
</TextView>
<EditText android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/etPhoneNumberInput"
android:hint="#string/returnNumber">
</EditText>
<Button android:id="#+id/addNumberEditText"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:freezesText="true"
android:editable="false"
android:text="ADD"
/>
<include
android:id="#+id/customedittext"
layout="#layout/myedittext"/>
<TextView android:id="#+id/emailPrint"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="#string/emailPrint">
</TextView>
<EditText android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/etEmailAddressInput"
android:hint="#string/returnEmail">
</EditText>
<Button
android:freezesText="true"
android:editable="false"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:id="#+id/btnSaveButton"
android:layout_width="wrap_content"
android:text="#string/save"
android:layout_below="#+id/emailInput"
/>
</LinearLayout>
Whenever I click on my button the action is heard but nothing is done. The layout of the page does not change even though the new edit text is in my list of edit texts and I am adding the new edit text to the layout.
Any help would be appreciated thanks.
It sure gets added but you are not seeing it cause there is no space left. Two things to test:
Place the LinearLayout inside a ScrollView.
Use the weight parameter.
Using the weight parameter:
EditText temp = new EditText(ContactEdit.this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT, 1);
temp.setLayoutParams(params);

Android not sizing Custom Dialog big enough

I am using a custom Dialog that contains a text field, an image, and a button. The text can contain HTML. Sometimes the bottom of the dialog gets chopped off the bottom when the text is long enough. How can I prevent this? I want Android to determine the size of the dialog but it doesn't seem to be doing that. DO I need to size the Dialog myself in this case?
Here is the layout...
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/alert_root_incorrect"
style="#style/AlertDialogTheme"
android:background="#drawable/rounded_alert"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/rounded_alert"
>
<TableLayout
android:stretchColumns="0"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TableRow>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:textStyle="bold"
android:text="Sorry, that's wrong!"
android:textColor="#color/gray_dark" />
<ImageView
android:id="#+id/check"
android:background="#drawable/xmark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="10dp" />
</TableRow>
</TableLayout>
<TextView
android:id="#+id/alert_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="none"
android:text="In fact, this is where the explanation will go. Something about how this passage related to the topic"
android:textColor="#000000" />
<Button
android:id="#+id/okay_button"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center_horizontal"
android:background="#drawable/rounded_alert_button"
android:text="Okay"
android:textColor="#color/white"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
And here is the code I am using to load it...
if ( null == layout ) {
this.layout = inflater.inflate(R.layout.alert_incorrect, (ViewGroup) findViewById(R.id.alert_root_incorrect));
}
TextView message = (TextView) layout.findViewById(R.id.alert_text);
message.setText(Html.fromHtml(card.getConclusion()));
((Button) layout.findViewById(R.id.okay_button)).setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dismissDialog(INCORRECT_DIALOG);
nextQuestion();
}
});
layout.requestLayout();
dialog = new Dialog(this, R.style.AlertDialogTheme);
dialog.setContentView(layout);
dialog.setCancelable(false);
return dialog;
And here's a snap of what I mean..
Thanks,
John
This is not perfect but I've corrected it by setting the layout of the dialog relative to the default display.
dialog = new Dialog(this, R.style.AlertDialogTheme);
dialog.setContentView(layout);
Window window = dialog.getWindow();
window.setLayout(
(int)(window.getWindowManager().getDefaultDisplay().getWidth() * .90),
(int)(window.getWindowManager().getDefaultDisplay().getHeight() * .90 ));
dialog.setCancelable(false);
Just tweak the ".90" values until it feels right.
Here is the solution:
You should add a Linearlayout at the outside of your dialog's xml file
Then set this Linearlayout's gravity as "center"
the last step is creating a LayoutParams and set it to the dialog
android.view.WindowManager.LayoutParams lp = new android.view.WindowManager.LayoutParams();
lp.width = android.view.WindowManager.LayoutParams.FILL_PARENT;
lp.height = android.view.WindowManager.LayoutParams.FILL_PARENT;
alertDialog.getWindow().setAttributes(lp);

Categories

Resources