Why is NoActionbar Theme affecting ScrollView & overall Layout? - android

So i have a layout in Android where its a vertical LinearLayout that encompasses A ScrollView, LinearLayout, LinearLayout.
I made each child take about roughly a 3rd of the screen. When I have them Holo or Holo.Light with an ActionBar is looks as expected:
However, when I change the Theme to Holo.NoActionBar or Holo.Light.NoActionBar, for some reason, it completely ignores my android:layout_weight, or even my ScrollView. Like all my contents in my scroll view are no longer collapsed.
It then looks like this:
Why does this happen? I cannont figure out why. I even made a custom theme in my styles.xml and the problem still existed. How come ScrollView only works when I have an ActionBar?
Here is my code:
<?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="match_parent"
android:orientation="vertical"
android:paddingTop="10dp"
android:weightSum="100"
>
<ScrollView
android:layout_height="0dp"
android:layout_width="fill_parent"
android:layout_weight="30">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/tvEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/email" />
<EditText
android:id="#+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textNoSuggestions" />
.......................
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_height="0dp"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_weight="40">
<Button
android:id="#+id/bSendEmail"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/sendEmail" />
</LinearLayout>
<LinearLayout
android:layout_height="0dp"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_weight="30">
<AnalogClock
android:id="#+id/analogClock1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>

Related

Scrollview does not scroll when keyboard appears

I have a few EditTexts in my RelativeLayout, and a button aligned at the bottom of it. When the keyboard pops up, I want my layout to resize (therefore, I'm using android:windowSoftInputMode="adjustResize") and also want it to be scrollable, because in smaller screens resizing it isn't enough.
The problem is I can't get it to scroll at all!
I do need the Button to stay at the bottom of the screen.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF">
<!-- some hidden RelativeLayouts, filling the whole screen -->
<RelativeLayout
android:id="#+id/form_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent" android:layout_height="match_parent"
android:fillViewport="true" android:layout_above="#+id/ok_btn">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" android:background="#99000000" android:visibility="visible">
<View
android:id="#+id/shade"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignTop="#+id/logradouro1"
android:background="#FFF" android:layout_marginTop="-30dp"/>
<!-- some visible EditTexts and TextViews here -->
</RelativeLayout>
</ScrollView>
<Button android:id="#+id/ok_btn"
android:layout_width="match_parent"
android:layout_height="50dp" android:background="#color/verdeBotao" android:text="Cadastrar"
android:textColor="#FFF" android:layout_alignParentBottom="true"/>
</RelativeLayout>
</RelativeLayout>
Below are 2 screenshots to illustrate what is happening. Please notice that I can't scroll when the keyboard is up.
Thanks!
i am posting something similar to your ui. take a RelativeLayout for the button at the bottom. set gravity to bottom and your button view should android:layout_alignParentBottom="true"
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/m_table_menu" >
<LinearLayout
android:id="#+id/layuserdetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:padding="5dp" >
Yourviewss......i guess edittexts
</LinearLayout>
</ScrollView>
//scrollable Button layout
<RelativeLayout
android:id="#+id/m_table_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:padding="0dp" >
<LinearLayout
android:id="#+id/laysharepost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:orientation="vertical"
android:padding="5dp" >
//replace textview with buttonview..
<TextView
android:id="#+id/share_tvcommentdone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/button_selector"
android:padding="10dp"
android:text="POST"
android:textColor="#android:color/white" />
</LinearLayout>
</RelativeLayout>

android Layouts overlapping ListView and LinearLayout

I am using FrameLayout in which I am having a search Textbox and Button and a ListView to be displayed in the next line of the TextBox
My layout is like this ,
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="#drawable/pattern1" />
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="top" >
<Button
android:id="#+id/btnadd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="addCustomers"
android:text="Add"
android:textColor="#000000" >
</Button>
<EditText
android:id="#+id/edtSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:ems="10"
android:hint="Search"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="60dp"
android:gravity="bottom"
android:orientation="vertical">
<ListView
android:id="#+id/list_customers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|center_horizontal" >
</ListView>
</LinearLayout>
</FrameLayout>
I am using this TextView to diplay List item in the ListView,
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/txtsimple_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:gravity="center_vertical"
android:textSize="20sp"
android:textStyle="bold" />
I have given margin top attribute for the ListView, but even though it overlaps on the Button and EditText controls.
I am using a FrameLayout but of no use. Please suggest me any help!!
Any help is appreciated!!
You should use LinearLayout as parent, just set android:orientation="vertical".
<?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" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="#drawable/pattern1" />
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="top" >
...
</LinearLayout>
<ListView
android:id="#+id/list_customers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|center_horizontal" >
...
</ListView>
</LinearLayout>
FrameLayout has no 'rules of placement' so everything just stacks on to each other.
Instead, use a LinearLayout with android:orientation="vertical"
or use a RelativeLayout and add positioning values to the childs, such as android:layout_below
+1 Neoh and remove imageview, instead put the image as background image attribute at parent view
android:background="#drawable/pattern1"
FrameLayout are used very less,beacuse they are used to display single view or views which overlaps each other.
So you should use RelativeLayout.
FrameLayout is not the best option. You can use other layouts, eg, GridLayout, RelativeLayout or ListView.

Android ScrollView not scrolling

I have solved my question. I chose to instead have a header and a footer that are always located at the bottom and top of the screen respectively. Then I created a "center content" which I enclosed within a ScrollView layout. I have updated the code below if people are interested in seeing what it now looks like.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="#FFFFFF">
<LinearLayout android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#layout/header"
android:layout_alignParentTop="true">
<ImageView android:src="#drawable/logo"
android:contentDescription="#string/logo_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"/>
</LinearLayout>
<ScrollView android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="350dip"
android:layout_below="#id/header">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dip" >
<!-- Email Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372C24"
android:text="#string/email"/>
<EditText android:id="#+id/email_field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:inputType="textEmailAddress"/>
<!-- Password Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:textColor="#372C24"
android:text="#string/password"/>
<EditText android:id="#+id/password_field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:inputType="textPassword"/>
<!-- Login button -->
<Button android:id="#+id/login_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dip"
android:text="#string/login"/>
<!-- Register button -->
<Button android:id="#+id/register_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dip"
android:text="#string/register_button"/>
</LinearLayout>
</ScrollView>
<LinearLayout android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="90dip"
android:background="#layout/footer"
android:layout_alignParentBottom="true">
</LinearLayout>
</RelativeLayout>
For me, remove android:windowSoftInputMode="adjustPan" of the <activity> tag in AndroidManifest.xml file solved the problem.
I removed this line from the AndroidManifest.xml file
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
and added this line
android:theme="#android:style/Theme.NoTitleBar"
it has both fixed my scrolling app and made my app look more visually appealing. However, I am not sure if this is the correct fix.
for me the problem was that the LinearLayout in the ScrowView had android:layout_height="wrap_content".
<ScrollView android:id="#+id/scroll_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout android:id="#+id/layout_inside"
android:layout_width="match_parent"
android:layout_height="wrap_content" --> This should not we wrap_content, but specific height.
android:orientation="vertical" >
The ScrollView is not working when used as the root element of an XML layout.
It has to be wrapped inside a LinearLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView android:id="#+id/scroll_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout android:id="#+id/layout_inside"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
Have a fun ! !
ScrollView must have Linearlayout control as a immediate child, you have relative layout, I think that might be causing the problem.
Check this link out, also this. Look at their layout xmls..

linear layouts not spacing correctly

Hey im having trouble with these linear layouts in android xml. initially i did them in a relative layout and it worked fine, but after some research i discovered that relative layouts inside of a scrollview doesnt work supposedly. so now after much tweaking my imageview shows up but has a huge margin above and below it and my textview doesnt even show up aside from being where its supposed to in the graphics editor but blank.
so whats wrong? should i even be using a linear layout?
this is roughly what its supposed to look like http://www.mediafire.com/view/?z945tz2vrb2x46t
and this is what it looks like after Abdul and Ralgha's help as well as setting the base linear layout's height to wrap content http://www.mediafire.com/view/?px17q2z3yyeo8az
Thanks
<LinearLayout 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" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/today"
android:src="#string/today"
android:textSize="30dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
<ImageView
android:id="#+id/image1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/weeklylist_blocks"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
`![screwed up layout][1]
Don't worry about weight right now, leave it removed. In your TextView, change "android:src" to "android:text" (without the quotes naturally). If that alone doesn't solve it, remove the textSize line and see what happens. If that works, then you can start playing with sizes (and weights if needed).
Also, textSize should be given in sp rather than dp. sp is for text, dp is for everything else, though that's not what is causing your problem.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="#+id/today"
android:textSize="30sp"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="#string/today"
/>
<ImageView
android:id="#+id/image1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/weeklylist_blocks"
/>
</LinearLayout>
</ScrollView>
android:layout_weight="1"
might be the cause of your problems
Its works like charm, Use the following coding to achieve your thing:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fillViewport="true" >
<LinearLayout
android:id="#+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/today"
android:src="#string/today"
android:textSize="30sp"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="#string/today"
/>
<ImageView
android:id="#+id/image1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:contentDescription="#string/nissan"
android:src="#drawable/weeklylist_blocks" />
</LinearLayout>
</ScrollView>
</LinearLayout>

How to make a edittext view fill the parent element in android

I have two edittext views. One of them has only one line, its the title. But the other one should fill the linearlayout to the end, but it doesn't.
I updated the code so this is my whole xml for this app. I hope someone can find what's wrong. The part that i want to form like this is the part inside the LinearLayout named addView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ffffff">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/addButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/addbuttonstyle"
android:layout_weight="20"/>
<ImageView
android:id="#+id/titleView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/titleview"
android:layout_weight="60"/>
<Button
android:id="#+id/orderButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/orderbuttonstyle"
android:layout_weight="20"/>
</LinearLayout>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/addView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="#+id/textBoxTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="note title"
android:singleLine="true"
/>
<EditText
android:id="#+id/textBoxContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hint="content"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/backgroundLayout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/background"
/>
</FrameLayout>
I changed textBoxTitle's height to wrap_content and I see this:
Is this what you were hoping for? Also if you want content to appear in the upper-left corner use this attribute:
<EditText
...
android:gravity="top"
/>
So i found what was wrong.
I needed to set layout_height (of the textBoxContent view) to 0dp and layout_weight (of the textBoxContent view) to 1.
The first view should have android:layout_width="wrap_content"

Categories

Resources