ScrollView inside my layout is not working. The question might be a silly one. I already wasted an hour with it.
Here is my XML layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="1100dp"
android:layout_height="1500dp"
android:fillViewport="true"
android:background="#f7f7f7"
android:layout_weight="1"
android:orientation="vertical"
android:padding="25dp" >
<LinearLayout
android:id="#+id/container"
android:layout_width="1100dp"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/account_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="ACCOUNT"
android:textColor="#f44b3b"
android:textSize="18dp" />
<LinearLayout
android:layout_width="900dp"
android:layout_height="2dp"
android:layout_marginBottom="10dp"
android:background="#f44b3b" >
</LinearLayout>
<RelativeLayout
android:layout_width="1100dp"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="Email"
android:textColor="#333333"
android:textSize="22dp" />
<EditText
android:id="#+id/email"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_marginLeft="300dp"
android:layout_toRightOf="#+id/textView1"
android:ems="10"
android:inputType="textEmailAddress" >
</EditText>
</RelativeLayout>
<LinearLayout
android:layout_width="900dp"
android:layout_height="1dp"
android:layout_marginBottom="10dp"
android:background="#c6c6c6" >
</LinearLayout>
<RelativeLayout
android:layout_width="1100dp"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/change_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="Change Password"
android:textColor="#333333"
android:textSize="22dp" />
<EditText
android:id="#+id/change_password_et"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_marginLeft="170dp"
android:layout_toRightOf="#+id/change_password"
android:ems="10"
android:inputType="text" >
</EditText>
</RelativeLayout>
<LinearLayout
android:layout_width="900dp"
android:layout_height="1dp"
android:layout_marginBottom="10dp"
android:background="#c6c6c6" >
</LinearLayout>
<RelativeLayout
android:layout_width="1100dp"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="Facebook"
android:textColor="#333333"
android:textSize="22dp" />
<EditText
android:id="#+id/facebook_et"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_marginLeft="255dp"
android:layout_toRightOf="#+id/facebook"
android:ems="10"
android:inputType="text" >
</EditText>
</RelativeLayout>
<LinearLayout
android:layout_width="900dp"
android:layout_height="1dp"
android:layout_marginBottom="10dp"
android:background="#c6c6c6" >
</LinearLayout>
<RelativeLayout
android:layout_width="1100dp"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/twitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="Twitter"
android:textColor="#333333"
android:textSize="22dp" />
<EditText
android:id="#+id/twitter_et"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_marginLeft="280dp"
android:layout_toRightOf="#+id/twitter"
android:ems="10"
android:inputType="text" >
</EditText>
</RelativeLayout>
<LinearLayout
android:layout_width="900dp"
android:layout_height="1dp"
android:layout_marginBottom="10dp"
android:background="#c6c6c6" >
</LinearLayout>
<TextView
android:id="#+id/profile_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Heading"
android:textColor="#f44b3b"
android:textSize="18dp" />
<LinearLayout
android:layout_width="900dp"
android:layout_height="2dp"
android:layout_marginBottom="10dp"
android:background="#f44b3b" >
</LinearLayout>
<RelativeLayout
android:layout_width="1100dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" >
<TextView
android:id="#+id/Gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="Gender"
android:textColor="#333333"
android:textSize="22dp" />
<Spinner
android:id="#+id/gender_spinner"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_marginLeft="280dp"
android:layout_toRightOf="#+id/Gender" />
</RelativeLayout>
<LinearLayout
android:layout_width="900dp"
android:layout_height="1dp"
android:layout_marginBottom="10dp"
android:background="#c6c6c6" >
</LinearLayout>
<RelativeLayout
android:layout_width="1100dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" >
<TextView
android:id="#+id/Birthday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="170dp"
android:text="Birthday"
android:textColor="#333333"
android:textSize="22dp" />
<Button
android:id="#+id/setDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/Birthday"
android:onClick="showDatePickerDialog"
android:text="Pick date" />
<EditText
android:id="#+id/birthdayet"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_toRightOf="#+id/Birthday"
android:ems="10"
android:inputType="text"
android:text="Birthday"
android:textColor="#f44b3b"
android:textSize="18dp" >
</EditText>
</RelativeLayout>
<LinearLayout
android:layout_width="900dp"
android:layout_height="1dp"
android:layout_marginBottom="10dp"
android:background="#c6c6c6" >
</LinearLayout>
<RelativeLayout
android:layout_width="1100dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" >
<TextView
android:id="#+id/zipcode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text="Zip Code"
android:textColor="#333333"
android:textSize="22dp" />
<EditText
android:id="#+id/zip"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_marginLeft="270dp"
android:layout_toRightOf="#+id/zipcode"
android:ems="10"
android:inputType="number" >
</EditText>
</RelativeLayout>
<LinearLayout
android:layout_width="900dp"
android:layout_height="1dp"
android:layout_marginBottom="10dp"
android:background="#c6c6c6" >
</LinearLayout>
<TextView
android:id="#+id/heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="COOL"
android:textColor="#f44b3b"
android:textSize="18dp" />
<LinearLayout
android:layout_width="900dp"
android:layout_height="2dp"
android:layout_marginBottom="8dp"
android:background="#f44b3b" >
</LinearLayout>
</LinearLayout>
</ScrollView>
Remove the
android:layout_weight="1"
android:orientation="vertical"
from the scroll view. And fill_parent the layout height..
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="1100dp"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#f7f7f7"
android:padding="25dp" >
Replaced this inside the ScrollView property
android:layout_width="fill_parent"
android:layout_height="fill_parent"
and also removed
android:layout_weight ="1"
This worked fine. Thanks to #TechEnd
Simply you have to change in Scrollview Property like as below :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#f7f7f7"
android:layout_weight="1"
android:orientation="vertical"
android:padding="25dp" >
From Manifest for this Activity Remove : "android:windowSoftInputMode="adjustPan"
It Will Work Surely.
You need to close your
< ScrollView> </ScrollView>
i don't see it or u just forget to post it ???
<ScrollView
android:layout_width="match_parent"
android:layout_height="40dp"
android:fadeScrollbars="false"
android:scrollbarStyle="insideInset"
android:scrollbarThumbVertical="#drawable/scrollview_thumb"
android:scrollbarTrackVertical="#drawable/custom_scroll_style">
<EditText
android:id="#+id/input_customer_email"
android:layout_width="match_parent"
android:layout_height="40dp"
android:clickable="false"
android:longClickable="false"
android:focusable="false"
android:inputType="textMultiLine"
android:hint="Customer's Email Address" />
</ScrollView>
In my case, the ListView will be holding an adapter for inflating a vertical stack of buttons. I've calculated and assigned the ListView height manually (in such a way that all buttons are expanded). The scrolling issue I had was, using ListView inside the ScrollView (where the scrolling happen, If I click outside the ListView's bounds and try to scroll. Whereas the scrolling won't happen, if I try to scroll by clicking inside the ListView's bounds). I went through multiple stackoverflow answers/android docs and also tried few custom ListView/LinearLayout (with adapter) but in the end nothing worked. Then, I understood the logic and made the ListView to have NestedScrolling implementation and it worked like charm.
I just made this change to my code
myListView.setNestedScrollingEnabled(true);
Related
I've an application where i place Radio Button & TextView on a same line . But When i run on Nexus 7 it looks like this :
I want to create to 2nd one .How can i solve this :
Here is my XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#drawable/loginsigninbackground" >
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="vertical" >
<EditText
android:id="#+id/UserNameToLogin"
android:layout_width="300dp"
android:layout_height="40dp"
android:hint="#string/username"
android:ems="10"
android:layout_gravity="center"
android:background="#drawable/customised_edit_text"
android:singleLine="true"
android:gravity="center|left"
android:textColorHint="#30D683"
android:paddingLeft="20dp"
>
<requestFocus />
</EditText>
<EditText
android:id="#+id/UserPasswordToLogin"
android:layout_width="300dp"
android:layout_height="40dp"
android:hint="#string/password"
android:ems="10"
android:inputType="textPassword"
android:layout_gravity="center"
android:background="#drawable/customised_edit_text"
android:singleLine="true"
android:gravity="center|left"
android:textColorHint="#30D683"
android:layout_marginTop="5dp"
android:paddingLeft="20dp"
>
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioButtonRememberMe"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/remember_me"
android:checked="false"
android:textSize="18sp"
android:textColor="#30D683"
android:button="#drawable/radio_selector"
android:background="#android:color/transparent" />
<TextView
android:id="#+id/UserRememberMe"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/forgot_password"
android:textColor="#30D683"
android:textSize="18sp"
android:cacheColorHint="#android:color/transparent"
android:background="#android:color/transparent"
/>
</LinearLayout>
<Button
android:id="#+id/ButtonNext"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="#string/next"
android:background="#drawable/customised_button_click"
android:onClick="gotosignup"
android:clickable="true"
android:textSize="20sp"
/>
<Button
android:id="#+id/ButtonSignUp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/signup"
android:gravity="center"
android:textSize="20sp"
android:background="#drawable/customised_button_click"
android:onClick="gotosignup"
android:clickable="true"
/>
</LinearLayout>
</LinearLayout>
May I know what is the correct way to achieve my objective?Maybe this question too basic, but i did't find any suitable solution.Please Help me out.
Do not hardcode the height and width of your edit-text like you did
<EditText
android:id="#+id/UserPasswordToLogin"
android:layout_width="300dp"
android:layout_height="40dp"
android:hint="#string/password"
android:ems="10"
android:inputType="textPassword"
android:layout_gravity="center"
android:background="#drawable/customised_edit_text"
android:singleLine="true"
android:gravity="center|left"
android:textColorHint="#30D683"
android:layout_marginTop="5dp"
android:paddingLeft="20dp"
>
so basically it is
android:layout_width="300dp"
android:layout_height="40dp"
instead of give fill_parent or match_parent
android:layout_width="match_parent"
android:layout_height="match_parent"
or
android:layout_width="fill_parent"
android:layout_height="fill_parent"
do this for all text field and then try.
Try this..
There are two ways
1) Change EditText width as match_parent for both android:layout_width="match_parent"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="vertical" >
<EditText
android:id="#+id/UserNameToLogin"
android:layout_width="match_parent"
android:layout_height="40dp"
android:ems="10"
android:gravity="center|left"
android:hint="username"
android:paddingLeft="20dp"
android:singleLine="true"
android:textColorHint="#30D683" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/UserPasswordToLogin"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:ems="10"
android:gravity="center|left"
android:hint="password"
android:inputType="textPassword"
android:paddingLeft="20dp"
android:singleLine="true"
android:textColorHint="#30D683" >
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioButtonRememberMe"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"
android:checked="false"
android:text="remember_me"
android:textColor="#30D683"
android:textSize="18sp" />
<TextView
android:id="#+id/UserRememberMe"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent"
android:cacheColorHint="#android:color/transparent"
android:text="forgot_password"
android:textColor="#30D683"
android:textSize="18sp" />
</LinearLayout>
<Button
android:id="#+id/ButtonNext"
android:layout_width="match_parent"
android:layout_height="60dp"
android:clickable="true"
android:onClick="gotosignup"
android:text="next"
android:textSize="20sp" />
<Button
android:id="#+id/ButtonSignUp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="center"
android:onClick="gotosignup"
android:text="signup"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
and
2) change your LinearLayout width as 300dp and also remove android:layout_gravity="center" for both EditText
<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioButtonRememberMe"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/remember_me"
android:checked="false"
android:textSize="18sp"
android:textColor="#30D683"
android:button="#drawable/radio_selector"
android:background="#android:color/transparent" />
<TextView
android:id="#+id/UserRememberMe"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/forgot_password"
android:textColor="#30D683"
android:textSize="18sp"
android:cacheColorHint="#android:color/transparent"
android:background="#android:color/transparent"
/>
</LinearLayout>
change root linearlayout as
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
and set layout width as 300dp in childlayout
<LinearLayout
android:layout_width="300dp"
android:layout_height="0dip"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="vertical" >
Dear All experts I have problem with using scrollView anyone please help.. the Error is showing that the ScrollView is useless and also in other form of mine is shows the same , how can I solve this and how can I make my forms and activities been scroll ??
`
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="#string/welcome"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_margin="30dp"
android:contentDescription="#+id/button1"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/username"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/password"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
style="android:buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="goToMain"
android:text="#string/log_in" />
<Button
android:id="#+id/button2"
style="android:buttonStyle "
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="register"
android:text="#string/registration" />
</LinearLayout>
</ScrollView>
`
You need a child container as LinearLayout, TableLayout or RelativeLayout in your ScrollView like this:
<ScrollView
... >
<LinearLayout
... >
<!-- Your views: TextView, LinearLayout, etc. -->
</LinearLayout>
</ScrollView>
According to the reference:
A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll
You should put all the other fields in a single Layout.. Like linear layout,relative layout. Your whole code should look like this
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="#string/welcome"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_margin="30dp"
android:contentDescription="#+id/button1"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/username"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/password"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
style="android:buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="goToMain"
android:text="#string/log_in" />
<Button
android:id="#+id/button2"
style="android:buttonStyle "
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="register"
android:text="#string/registration" />
</LinearLayout>
</LinearLayout>
</ScrollView>
"Scrollview can host only one direct child"
Put all your stuff in some Layout e.g LinearLayout
I have been reading many posts here in stackoverflow about making a linear layout scroll and have applied all the specific advices to make it work but it still does not show on the left hand side. I am new to android and not sure what i am doing wrong.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scrollView1">
<LinearLayout
android:id="#+id/expense"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="start"
android:orientation="vertical"
tools:context=".Expense" >
<LinearLayout
android:id="#+id/tedsts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/rounded"
android:clickable="true"
android:weightSum="1.0" >
<TextView
android:id="#+id/testffg"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".30"
android:text="Matter"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/tedssss"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".65"
android:ellipsize="end"
android:paddingLeft="10dp"
android:singleLine="true"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:layout_width="15dp"
android:layout_height="wrap_content"
android:layout_weight="0.05"
android:src="#drawable/r_arrow" />
</LinearLayout>
<TextView
android:id="#+id/tetxttx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginLeft="0dp"
android:layout_marginRight="10dp"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/gray_dark"
android:visibility="invisible" />
<EditText
android:id="#+id/teetttsss"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/rounded_all"
android:ems="10"
android:gravity="top"
android:hint="dgdfgfgf"
android:inputType="textMultiLine" />
<LinearLayout
android:id="#+id/tesssstt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/rounded_all_clickable_selector"
android:clickable="true"
android:weightSum="1.0" >
<TextView
android:id="#+id/yttrree"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".20"
android:text="Date"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/rrrefffe"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".75"
android:ellipsize="end"
android:paddingLeft="10dp"
android:singleLine="true"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:layout_width="15dp"
android:layout_height="wrap_content"
android:layout_weight="0.05"
android:src="#drawable/r_arrow" />
</LinearLayout>
<RadioButton
android:id="#+id/dfgrrrrr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginTop="5dp"
android:text="Cost"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/gergrerrr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-4dp"
android:background="#drawable/rounded_all_clickable"
android:ems="10"
android:hint=""
android:inputType="numberDecimal"
android:singleLine="true" >
</EditText>
<RadioButton
android:id="#+id/rerreee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginTop="5dp"
android:text="Time"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/gggrrrrre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/roundede"
android:ems="10"
android:hint="grrrergg."
android:inputType="numberDecimal"
android:singleLine="true"
android:visibility="gone" >
</EditText>
<EditText
android:id="#+id/65gfhhggf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-4dp"
android:background="#drawable/rounded"
android:ems="10"
android:hint=""
android:inputType="numberDecimal" >
</EditText>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/gfhgfhtrhrth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="50dp"
android:layout_marginTop="15dp"
android:visibility="gone" />
<TextView
android:id="#+id/ghjjhhhgh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/expense_TV_total"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageButton
android:id="#+id/hgjhhghjhg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/save_selector" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
use this :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView ...>
<LinearLayout ...>
...
...
</LinearLayout>
</ScrollView>
and set hieght to
android:layout_height="wrap_content"
as Karakuri said
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
//Your Main Layout
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="100">
// First Sub Layout Under Main Layout
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="10"
android:weightSum="100" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="TextView"
android:layout_weight="70" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="30" />
</LinearLayout>// Finishing First Sub layout
// Second Sub Layout Under Main Layout
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_weight="10"
android:weightSum="100" >
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="TextView"
android:layout_weight="70" />
<EditText
android:id="#+id/editText2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="30" />
</LinearLayout>// Finishing Second Sub layout
similarly for 3rd,4rth,5th sub layouts and so on........
</LinearLayout> // Finishing Main Layout
</ScrollView> // Finishing ScrollView
Make the child of the ScrollView have android:layout_height="wrap_content" (currently yours has match_parent)
add
android:layout_width="match_parent"
android:layout_height="match_parent"
to your root ScrollView
I hope this code may be help you.
android:layout_width="match_parent"
android:layout_height="match_parent">
I'm trying to get the ListView to remain the same size even if it overflows. However, once the ListView overflows, it pushes the buttons below off the screen. How do I prevent it from pushing other elements that are below it?
As you can see from the above images, the second shows that the buttons get pushed off the screen once the ListView overflows.
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/splash_bg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:background="#color/splash_bg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:orientation="vertical" >
<TextView
android:id="#+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20sp"
android:paddingBottom="10dp"
android:textColor="#color/splash_text"
android:text="#string/sub" />
<EditText
android:id="#+id/grp_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/field1"
android:lines="1" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/members"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textSize="15sp"
android:paddingTop="5dp"
android:textColor="#color/splash_text"
android:text="#string/members" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/splash_bg"
android:orientation="horizontal" >
<EditText
android:id="#+id/name"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/field2" />
<Button
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add" />
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:background="#color/splash_bg" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:paddingTop="10dp" >
<Button
android:id="#+id/save_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="Save" />
<Button
android:id="#+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
Changet
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:background="#color/splash_bg" />
to
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:paddingLeft="5dp"
android:background="#color/splash_bg" />
You can use a relative layout for this. Modify the below according to your needs
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginRight="11dp"
android:layout_marginTop="11dp"
android:text="Create New Group" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="23dp"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editText1"
android:layout_marginLeft="11dp"
android:layout_marginTop="18dp"
android:text="Members" />
<EditText
android:id="#+id/editText2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/textView1"
android:layout_below="#+id/textView2"
android:layout_marginTop="31dp"
android:ems="10" />
<ListView
android:id="#android:id/list"
android:layout_above="#+id/button1"
android:layout_below="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
/>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText2"
android:layout_alignBottom="#+id/editText2"
android:layout_alignParentRight="true"
android:layout_marginRight="13dp"
android:text="ADD" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/button3"
android:layout_below="#android:id/list"
android:text="Cancel" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/textView1"
android:text="Save" />
</RelativeLayout>
I added this line : android:layout_weight="1" to the LinearLayout where EditText exist (my problem source) and the problem is gone !
look at the code where I commented <!-- HERE!!! -->
LOL I know i'm very late to answer this Q ,, sorry ,, but for anyone who is still struggling !
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/linearLayout1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="ID : "
android:layout_margin="#dimen/EdgeMargins"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/editText"
android:layout_margin="#dimen/EdgeMargins"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearLayout2"
android:layout_weight="1"> <!-- HERE!!! -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Any Notes :"
android:id="#+id/textView2"
android:layout_margin="#dimen/EdgeMargins"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_margin="#dimen/EdgeMargins" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Done"
android:id="#+id/button"
android:layout_margin="#dimen/EdgeMargins" />
</LinearLayout>
i had my problem with the highlighted EditText in the pic ,,, it expands with the entered text and pushes the DONE Button down !
I know my solution may look so silly but I took a whole day to solve this !
Hope it helps ^_^ GL
Hey guys, im pretty new to android platform and have a really simple question. Im putting buttons as layouts with text boxes, but im running out of room. How would i make it possible for the user to scroll down to view more buttons and stuff. For example, if i have 6 buttons, and 3 are in the field of view, i wanna be able to scroll with my finger and be able to see those buttons as I scroll.
Thanks for the help guys
-Localgamer
You can put your controls(widgets: buttons, labels etc) inside a ScrollView. Check the documentation of the class for details : http://developer.android.com/reference/android/widget/ScrollView.html
Something like:
<ScrollView ..>
<TextView .../>
<Button .../>
</ScrollView>
Try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/proffrag"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#ffffff"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="30dip"
android:paddingRight="30dip"
android:paddingTop="10dip" >
<EditText
android:id="#+id/firstname"
style="#style/custom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rounded_edittext"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
android:drawableLeft="#drawable/usernamem"
android:drawablePadding="10dp"
android:ems="10"
android:hint="#string/firstname"
android:inputType="textCapWords"
android:singleLine="true" >
<requestFocus />
</EditText>
<View
android:layout_width="fill_parent"
android:layout_height="10dp" />
<EditText
android:id="#+id/lastname"
style="#style/custom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rounded_edittext"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
android:drawableLeft="#drawable/usernamem"
android:drawablePadding="10dp"
android:ems="10"
android:hint="#string/lastname"
android:inputType="textCapWords"
android:singleLine="true" />
<View
android:layout_width="fill_parent"
android:layout_height="10dp" />
<EditText
android:id="#+id/username"
style="#style/custom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rounded_edittext"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_#-."
android:drawableLeft="#drawable/usernamem"
android:drawablePadding="10dp"
android:ems="10"
android:hint="#string/username"
android:singleLine="true" />
<View
android:layout_width="fill_parent"
android:layout_height="10dp" />
<EditText
android:id="#+id/email"
style="#style/custom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rounded_edittext"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_#-.,"
android:drawableLeft="#drawable/emailm"
android:drawablePadding="10dp"
android:ems="10"
android:hint="#string/email"
android:inputType="textEmailAddress"
android:singleLine="true" />
<View
android:layout_width="fill_parent"
android:layout_height="10dp" />
<TextView
android:id="#+id/selecttopic"
style="#style/custom"
android:layout_width="match_parent"
android:layout_height="20dp"
android:ems="10"
android:singleLine="true"
android:text="#string/selecttopic" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radiosubject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/rbtn_selector"
android:button="#null"
android:gravity="center"
android:padding="5dp"
android:text="Subject"
android:textColor="#drawable/rbtn_textcolor_selector" />
<RadioButton
android:id="#+id/radiocourse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/rbtn_selector"
android:button="#null"
android:gravity="center"
android:padding="5dp"
android:text="Courses"
android:textColor="#drawable/rbtn_textcolor_selector" />
</RadioGroup>
<View
android:layout_width="fill_parent"
android:layout_height="10dp" />
<TextView
android:id="#+id/selectgen"
style="#style/custom"
android:layout_width="match_parent"
android:layout_height="20dp"
android:ems="10"
android:singleLine="true"
android:text="#string/selectgen" />
<RadioGroup
android:id="#+id/radioGroup2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radiomale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/rbtn_selector"
android:button="#null"
android:gravity="center"
android:padding="5dp"
android:text="#string/selectmale"
android:textColor="#drawable/rbtn_textcolor_selector" />
<RadioButton
android:id="#+id/radiofemale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/rbtn_selector"
android:button="#null"
android:gravity="center"
android:padding="5dp"
android:text="#string/selectfemale"
android:textColor="#drawable/rbtn_textcolor_selector" />
</RadioGroup>
<View
android:layout_width="fill_parent"
android:layout_height="10dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/proftextgender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<Button
android:id="#+id/browse"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/mycustom_button"
android:minHeight="40dp"
android:text="#string/browse"
android:textColor="#ffffff" />
</RelativeLayout>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="10dp" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<LinearLayout
android:id="#+id/firs"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:orientation="horizontal"
android:paddingLeft="20dp" >
<TextView
android:id="#+id/browseimage"
android:layout_width="109dp"
android:layout_height="wrap_content"
android:layout_weight="1.17"
android:maxLines="2" />
</LinearLayout>
<View
android:id="#+id/vi"
android:layout_width="20dp"
android:layout_height="fill_parent"
android:layout_toRightOf="#id/firs" >
</View>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="#id/vi"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="#+id/upload"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mycustom_button"
android:minHeight="30dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="#string/upload"
android:textColor="#ffffff" />
</LinearLayout>
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="5dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_horizontal"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingLeft="30dp"
android:paddingRight="30dp" >
<Button
android:id="#+id/savechagnes"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/mycustom_button"
android:minHeight="40dp"
android:text="#string/savechanges"
android:textColor="#ffffff" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="5dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>