I try to create a from application, in the app I have a lengthy form which I want to be in a scroll view, But when I add EditText to the scrollView ..the eclipse shows some error in its designer view.
error!
IllegalStateException: ScrollView can host only one direct child
Exception details are logged in Window > Show View > Error Log
Any one have an idea to crack it out?
I have included this code after getting a solution for the above trouble..!
Now the EditText is not showing any typed text, it just gives some suggestions...!
I have the following XML :
<ScrollView
android:id="#+id/widget64"
android:layout_width="320px"
android:layout_height="358px"
android:fillViewport="true"
android:isScrollContainer="true"
android:saveEnabled="true">
<TableLayout
android:id="#+id/widget58"
android:layout_width="320px"
android:layout_height="65px"
android:orientation="vertical"
>
<TableRow
android:id="#+id/widget60"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/user"
android:text="User"
android:textColor="#000000">
</TextView>
</TableRow>
<TableRow
android:id="#+id/widget60"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
>
<EditText
android:id="#+id/users_first_name"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:hint="First Name"
android:focusable="true"
android:inputType="textPersonName"
android:enabled="true"
android:ems="15">
</EditText>
</TableRow>
</TableLayout>
</ScrollView>
Found the trouble.....
My emulator key was set to Chinese instead of English...
First add any layout to that scrollview and then add edittext to that layout.Then automatically u got the scrolling for that edittext .For Ex:add Linearlayout to that scrollview and then add editText to taht linearlayout.
Yes, ScrollVew can have only one child.
For this do something like this
<ScrollView
fillViewPortView = "true">
<RelativeLayout>
// Design the entire layout in here
// Put your elements one below the other. It will automatically scroll
// dont forget to setFillViewPort view to true in ScrollView
</RelativeLayout>
</ScrollView>
This will solve the problem for sure
Hope his help : )
Related
I have a keyword search option with EditView and a button in my android app, which in ADT looks perfect.
But when i run the program, the EditView expand beyond the viewing area and search button disappears because it goes out of page.
Xml for this is:
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/detail_ll"
style="#style/search_bg_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/keyword_detail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:ems="10"
android:hint="#string/keyword" />
<Button
android:id="#+id/button_search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="#string/search" />
</LinearLayout>
</TableRow>
Please help me in getting this in viewing area..
can you post the entire xml?
i mean with the
<TableLayout />
main tag
try setting android
android:layout_weight="1"
for both
or try android:layout_weight="1.5"
for edit text and
android:layout_weight="0.5"
for the button
I think you should make the android:layout_width="wrap_content" to android:layout_width="match_parent" or any fixed width (in dps) in the TableRow element.
layout_weight attribute divides a pre-known space according to its weight which is not present in this case.
Here you have to TableRow and LinearLayout height MatchParent and
give Weightsum="1" to LinearLayout it will fixed your problem and also remove android:ems property from Edittext
Hope this Help you.
This problem I am going to introduce, only happen in Android 4.0 +
I have a LinearLayout with 4 TableLayout, it's parent is a ScrollView.
I add TableRows dynamically into each TableLayout.
My TableRows are like this.
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/borda"
android:layout_margin="10dip"
android:paddingLeft="10dip"
>
<LinearLayout
android:id="#+id/l1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dip"
android:layout_marginBottom="15dip"
>
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/nome"
android:textStyle="bold"
android:textColor="#526691"
android:textSize="15sp"
android:paddingLeft="10dip"
android:paddingRight="5dip"
/>
<EditText
android:id="#+id/valorLabel"
android:layout_width="140dip"
android:layout_height="wrap_content"
android:textSize="15sp"
android:background="#ffffffff"
android:singleLine="true"
android:inputType="textCapSentences"
android:textColor="#777777" />
</LinearLayout>
</TableRow>
It seems to have a problem when the focused EditText is scrolled to out of the screen.
Question
How can I know if the EditText is visible in the screen? Is there a way of remove focus in the EditText if it's parent is scrolled?
Second Question
Why my TableRow's background get white when EditText is focused ?
here is the answer of the first question:
Android: how to check if a View inside of ScrollView is visible?
second one, you can set OnTouchListener on the parent view. When scrolled, its x or y value changes, then do clearFocus() on the EditText. Here is a good reference, check the Touch Event Listener part:
http://www.techotopia.com/index.php/Android_Touch_and_Multi-touch_Event_Handling
If you put your source code and the error log, you would get much better specific answer.
I have a relative layout which contains only the edit text view. But when content of edittext increases, my title bar gets shifted upwards. Most of the solutions I went through addresses the issue of shifting title bar when keyboard pops out. But I didn't found anything in case its content increases. I also used android:isScrollContainer="false" as suggested in this post How to avoid soft keyboard pushing up my layout?, but still the same issue. Is there a way to prevent it? Here is my xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="false"
android:background="#drawable/background" >
<EditText
android:id="#+id/hidden_edit_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="flagNoExtractUi"
android:inputType="textMultiLine"
android:singleLine="false"
android:paddingLeft="10sp"
android:paddingTop="5sp"
android:paddingRight="5sp"
android:scrollbars="vertical"
android:background="#android:color/transparent"
android:textSize="26sp" >
</EditText>
</RelativeLayout>
I managed to solve this issue by putting edittext in scrollview and replacing adjustPan with adjustSize in the manifest. This is the final working layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background">
<EditText
android:id="#+id/hidden_edit_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:imeOptions="flagNoExtractUi"
android:inputType="textMultiLine"
android:paddingLeft="10sp"
android:paddingRight="5sp"
android:paddingTop="5sp"
android:singleLine="false"
android:textSize="25sp" >
</EditText>
</ScrollView>
try to run your code after removing :
android:background="#android:color/transparent"
make your relative layout height and width to wrap_content.......... probably works. since when text increases your complete layout shifts. Try it and please rpy
Usually this can be solved by adding the android:windowSoftInputMode="adjustPan" property to your activity in the AndroidManifest file.
I am trying to implement the following:
Please check the image here:
The problem is whenever the user taps the compose mail edittext field, the send/save/discard buttons are hidden by the softkeyboard.
Any ideas on how to make those buttons always visible?
Thanks.
[EDIT]
Finally got it solved!Had to use Linearlayout instead of RelativeLayout and assigning proper layout_weight parameter did the trick. Thanks a lot Femi for pointing out that the buttons need to be outside of the ScrollView.
Here is the final working layout xml in case anyone finds it helpful:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"><ScrollView android:layout_alignParentTop="true"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<EditText
android:id="#+id/editTextCompose"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:gravity="top"
android:singleLine="false" android:lines="5"
android:inputType="text"
android:layout_below="#+id/editTextSubject"
>
</EditText>
</RelativeLayout>
</ScrollView><TableLayout android:id="#+id/recipeButtons"
android:background="#B0B0B0" android:padding="3dip"
android:stretchColumns="0,1" android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow android:gravity="center">
<Button android:id="#+id/editOtherAdditionButton"
android:text="Save" />
<Button android:id="#+id/removeOtherAdditionButton"
android:text="Delete" />
</TableRow>
</TableLayout></LinearLayout>
As documented in #mayra's answer to Android soft keyboard covers edittext field you should see http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft for the details to control.
Modifying the Activity's entry in the AndroidManifest to adjustResize should I think do it.
There is another question about this here, but it looks like the best approach is using the windowSoftInputMode
I'd like to change weight of a ViewFlipper programmatically.
I have a TableRow in which I have 2 columns. The first column contains a RelativeLayout element when the second column contains a ViewFlipper.
My ViewFlipper contains 2 views. Somehow in my Java code, I change the visible view of my ViewFlipper when I click on a button. What I want to do is to be able, when I change the ViewFlipper view (by calling showNext()), to change the ViewFlipper weight in order for it to be larger in the screen.
In other words, the first column of my row has a weight=1 and the second (the ViewFlipper) has a weight=0.8. When I click on a button I want to change those weights programmatically.
Is that possible ? How ? Below is my XML code.
I've searched on the Web, I found this solution:
myFlipper.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.3f));
This doesn't work, it crashes, which is, I think normal as the ViewFlipper isn't a LinearLayout.
Here is my XML code:
<TableRow
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#00000000" >
<RelativeLayout
android:id="#+id/rltest"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_centerInParent="true"
android:paddingLeft="6px"
android:paddingRight="6px"
android:background="#00000000" >
<TextView
android:id="#+id/tvtest"
android:layout_width="match_parent"
android:layout_height="60px"
android:layout_alignParentLeft="true"
android:textColor="#FFFFFF"
android:textSize="22px"
android:singleLine="true"
android:background="#00000000"
android:gravity="center_vertical" />
</RelativeLayout>
<ViewFlipper
android:id="#+id/flipper"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:background="#00000000" >
<TextView
android:id="#+id/tvName"
android:layout_width="wrap_content"
android:layout_height="60px" />
<LinearLayout
android:id="#+id/lltest"
android:layout_width="match_parent"
android:layout_height="60px"
android:layout_centerInParent="true"
android:background="#00000000"
android:gravity="center" />
</ViewFlipper>
</TableRow>
Do you have any idea ?
Thanks
My guess: you should be using TableRow.LayoutParams, not LinearLayout.LayoutParams. But that's just a guess without seeing the actual error; any time you ask a question about a crash on SO you should really include the log with the traceback of your error.