Unable to scroll - java

Please have a look at the following android xml file which is responsible for creating GUI
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/imageTitle"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:text="#string/imageDate"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="254dp"
android:layout_weight="0.34"
android:src="#drawable/test_image" />
<TextView
android:id="#+id/textView3"
android:layout_width="fill_parent"
android:layout_height="136dp"
android:text="#string/imageDescription" />
</LinearLayout>
</ScrollView>
I am trying to scroll the whole screen, but it is not happening. The uploaded images will make it clear to you. Why it is not scrolling? I am new to android and this is my second app. Please help!

for using scroll view, if u have entire view to be scrollable, use scroll view as parent layout and use code like this.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
here android:fillViewport="true" this is important part which allows u to fill the entire screen for your layout. if any other issue ask .
As android.developer says for fillViewport Defines whether the scrollview should stretch its content to fill the viewport.

Change this 2 like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/imageDescription" />

I think you should use wrap_content in the LinearLayout

Related

List view - auto modify height

I'm learning Android and now I have this tutorial: http://www.informit.com/articles/article.aspx?p=1928230
I modify (I want scroll all page) this and i have:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/petList"
android:layout_width="wrap_content"
android:layout_height="700dp" //here!!!!
android:divider="#000"
/>
<Button
android:id="#+id/ButtonAddNews"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add new Pet" >
</Button>
</LinearLayout>
</ScrollView>
Single item:
<LinearLayout
android:id="#+id/relative"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:padding="5dp"
orientation="horizontal">
<TextView
android:id="#+id/TextView01"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textColor="#f00"
android:layout_alignParentLeft="true"
android:text="two" ></TextView>
<TextView
android:id="#+id/TextView02"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textColor="#f00"
android:text="three"
android:layout_alignParentRight="true"></TextView>
</LinearLayout>
This working ok, but i must modify android:layout_height.
For example if i have 3 item in list then 700dp it is too more.
If I use fill_parent, match_parent or wrap_content then this show me only one item (I can scroll it).
What I have to type in the layout_height to automatically expanding, with the number of items?
First of all: REMOVE THAT SCROLLVIEW!! Never place a ListView inside a ScrollView! Google for "android listview inside scrollview" to get more information about that.
Now, usually you would implement that layout somehow like that:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/petList"
android:layout_width="wrap_content"
android:layout_height="0dp" // set layout_height=0dp
android:layout_weight="1" // add layout_weight=1
android:divider="#000"
/>
<Button
android:id="#+id/ButtonAddNews"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add new Pet" >
</Button>
</LinearLayout>
This way the list will use the whole available height, except what the button is using. If you want the button to scroll with the list, use a list footer.

How to layout a VideoView next to TextView with scrolling list underneath

I'm trying to have a VideoView fixed on the upper left with a TextView immediately to the right of it. Below both of those I want a scrollable list of checkboxes, and below that two buttons "prev" and "next". The VideoView and TextView should not scroll, just the checkboxes and buttons. I can't seem to make this work with Linear layouts so i tried RelativeLayout but it seem kinda clunky because I'm hard coding all the relative stuff. What's the best way of laying out this type of thing?
thanks,
Justin
Here is a basic layout that fits your description:
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<VideoView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<CheckBox android:id="#+id/chk1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<CheckBox
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/chk1"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
If the VideoView is to big maybe you'll want to limit the space available to it by using the 0dp value and layout_weight attribute on the enclosing LinearLayout.

Button in Android XML Layout

I'm working with a package some fellow members found for me that allows a slider to start at the top and slide to the bottom. I need to add content behind the slider, but I'm unsure of where to put it in the XML. Maybe I have to add a linear layout, but I'm not sure. I just need to add one button that sits in the very center of the screen. I think it needs to be put in the following code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:ns="http://schemas.android.com/apk/res/it.sephiroth.demo.slider">
<Button
android:id="#+id/button_open"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/open"
android:layout_centerInParent="true"
android:visibility="gone" />
<it.sephiroth.demo.slider.widget.MultiDirectionSlidingDrawer
xmlns:my="http://schemas.android.com/apk/res/it.sephiroth.demo.slider"
android:id="#+id/drawer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
ns:content="#+id/content"
ns:direction="topToBottom"
ns:handle="#+id/handle" >
<include
android:id="#id/content"
layout="#layout/pen_content" />
<ImageView
android:id="#id/handle"
android:layout_width="wrap_content"
android:layout_height="40px"
android:src="#drawable/sliding_drawer_handle_bottom" />
</it.sephiroth.demo.slider.widget.MultiDirectionSlidingDrawer>
</RelativeLayout>
I'd also like for the button to be behind the drawer.
Any help would be great!
Try This:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:ns="http://schemas.android.com/apk/res/it.sephiroth.demo.slider">
<LinerLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button_open"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/open"
android:layout_centerInParent="true"
android:visibility="gone" />
</LinerLayout

android: image in icon not showing

I'm trying to place a banner at the top of a listview, one that stays there when the list scrolls down. The layout I currently have actually show what I want in the preview but when I run it in the emulator the only thing that appears is the list.
The XML is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:src="#drawable/edinburghcrest"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="#+id/EdUniCrest" android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"></ImageView>
<TextView android:layout_height="wrap_content" android:id="#+id/banner"
android:text="Hotels Nearby" android:textColor="#FFFFFF"
android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content"
android:layout_alignParentTop="true" android:layout_toRightOf="#+id/EdUniCrest"
android:layout_alignParentRight="true" android:layout_alignBottom="#+id/EdUniCrest"
android:background="#25476C"></TextView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#color/listcolor" android:orientation="vertical" android:layout_marginTop="50dp">
<ListView android:id="#android:id/list" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
<TextView android:id="#android:id/empty" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="#string/no_lunchs" />
</LinearLayout>
Anyway, I can't see why it isn't working. Does anyone have any idea what it might be?
Thanks.
The RelativeLayout here just makes it confusing. You can achieve this simply with a couple of LinearLayouts. Wrap your banner in a horizontal layout with a height=wrap_content and set you ListView to height=fill_parent. The list will then fill all available space. The List will scroll independently of the rest of the page.
Something like below should work:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:orientation="horizontal" android:id="#+id/bannerBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:src="#drawable/edinburghcrest"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="#+id/EdUniCrest"/>
<TextView android:layout_height="wrap_content" android:id="#+id/banner"
android:text="Hotels Nearby" android:textColor="#FFFFFF"
android:gravity="center" android:textSize="20dp" android:layout_width="wrap_content"
android:background="#25476C"/>
</LinearLayout>
<ListView android:id="#android:id/list" android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView android:id="#android:id/empty" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:text="#string/no_lunchs" />
</LinearLayout>
What if you wrapped your RelativeLayout in a ScrollView, and since a ScrollView can only have one child, put the banner above it?

Android Wear: Layout is not displaying properly in Emulator

I'm developing an Android smart watch application. The initial screen appears fine. But, when I go to next screen, the upper part pops up with the name of project something like this. In the below image, Watch is the name of the project.
I want to see the entire screen instead of white space which contains project's name. Does anyone know how to solve it and why is it appearing?
My XML file is
<?xml version="1.0" encoding="utf-8"?>
<android.support.wear.widget.BoxInsetLayout 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:orientation="vertical"
tools:deviceIds="wear">
<LinearLayout
android:id="#+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/black"
android:weightSum="1"
tools:ignore="UselessParent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<LinearLayout
android:id="#+id/sign_up_top_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:layout_marginTop="15dp">
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="5dp"
android:textAlignment="center"
android:textSize="18sp"
android:text="#string/text"
android:background="#color/black"
android:textColor="#color/white"
android:fontFamily="Century-Gothic.ttf" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="18dp"
android:layout_height="19dp"
android:layout_toRightOf="#+id/text"
android:src="#drawable/fingerprint" />
</LinearLayout>
<Button
android:layout_marginTop="10dp"
android:id="#+id/button"
android:background ="#drawable/roundedbutton"
android:text="#string/button_text"
android:layout_width="108dp"
android:textAlignment="center"
android:drawablePadding="20dp"
android:layout_gravity="center"
android:textColor="#color/white"
android:layout_height="75dp"
android:layout_weight="0.34" />
</LinearLayout>
</android.support.wear.widget.BoxInsetLayout>
Use a BoxInsetLayout for your root layout:
This class applies the required window insets depending on the screen
shape and lets you easily align views on the center or near the edges
of the screen.
And I would highly recommend you to read through this tutorial.
Edit 2:
You need to use:
android.support.wearable.view.BoxInsetLayout
not:
android.support.wear.widget.BoxInsetLayout
and add to the mainContainer:
app:layout_box="all"
<android.support.wearable.view.BoxInsetLayout
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:orientation="vertical"
tools:deviceIds="wear">
<LinearLayout
app:layout_box="all"
android:id="#+id/mainContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/black"
android:weightSum="1"
tools:ignore="UselessParent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
The answer to the question was simple. I figured out after one day. I changed my theme from Theme.AppCompat.Light to Theme.AppCompat.Light.NoActionBar in Manifest file. The program name bar disappeared.

Categories