ScrollView Does not Scrolll Smoothly - java

I am adding a ScrollView and several TextView together. I am populating data using a web service (php/mysql data from server). Everything is fine except one issue. When user scrolls the page/activity, the scroll is not as smooth as a listview.
I am posting my xml here:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:focusable="true"
android:id="#+id/scrolFullText"
tools:context=".FullText" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="#+id/HEAD"
android:text="#string/HEAD"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="#color/blue"
/>
<TextView
android:id="#+id/WRITER"
android:text="#string/WRITER"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#color/darkgreen"
/>
<TextView
android:id="#+id/CATEGORY"
android:text="#string/CATEGORY"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dp"
/>
<TextView
android:id="#+id/TEXT"
android:text="#string/TEXT"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dp"
/>
</LinearLayout>
</ScrollView>
How can I make my scroll a little smoother?

The scroll may be not smooth because some background job is being processed, you may test your app on multiple devices.
By the way I guess the ScrollView height should be match_parent

Related

Support screen issue

I added support screen for different sizes for the devices but when i test it it seems that the buttons are a bit up,not like in the preview(I have the same phone as the preview).
Here's the layout for my phone specs:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#drawable/backgroundapp"
android:orientation="vertical">
<ImageButton
android:id="#+id/btnSwitch"
android:layout_width="110dp"
android:layout_height="120dp"
android:src="#drawable/poweroffline"
android:background="#null"
android:contentDescription="#null"
android:layout_marginTop="64dp"
android:scaleType="fitXY"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:clickable="false" />
<ImageButton
android:id="#+id/FlashBlinkButton"
android:layout_width="75dp"
android:layout_height="100dp"
android:src="#drawable/blinkoffline"
android:background="#null"
android:contentDescription="#null"
android:scaleType="fitCenter"
android:layout_below="#+id/btnSwitch"
android:layout_alignLeft="#+id/AlarmButton"
android:layout_alignStart="#+id/AlarmButton"
android:layout_marginTop="12dp" />
<ImageButton
android:layout_width="75dp"
android:layout_height="60dp"
android:id="#+id/AlarmButton"
android:src="#drawable/alarmoffline"
android:background="#null"
android:contentDescription="#null"
android:scaleType="fitXY"
android:layout_marginTop="19dp"
android:layout_below="#+id/FlashBlinkButton"
android:layout_centerHorizontal="true" />
</RelativeLayout>
I also have another device where it's like the other one a bit up even when i put the configuration qualifiers .
You will never achieve a fool-proof layout with this techique. Try adding the background of the button (the embossed circles) to the ImageButtons instead, they will move together with the buttons and nothing will be off-center.

A button wont show up

I have this xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.gelasoft.answeringball.MainActivity$PlaceholderFragment" >
<ImageView
android:id="#+id/sphereIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/magicBallDescr"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:id="#+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/sphereIcon"
android:orientation="horizontal" >
<TextView
android:id="#+id/txtAnswer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:id="#+id/launch_codes"
android:layout_width="match_parent"
android:layout_height="106dp"
android:hint="#string/textHint"
android:inputType="text" />
<Button
android:id="#+id/btnAsk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/btnAskQ"
/>
</LinearLayout>
</RelativeLayout>
Everything is perfect, but the button won't show up.
What am I missing here? I know that is something basic even for a beginner, but I find it hard to understand as a newbie in the xml world.
Your inner LinearLayout has the orientation 'horizontal'. I guess your view can't show the TextView, EditText and Button in one row. There isn't that much space.

Why does the GridView keeps resizing iteself?

I am trying to implement a GridView in my Android app, but it seems the GridView keeps resizing. I have attached a video of this below (notice the scrollbar). Although its subtle, but it's really annoying and hampers with parallax scrolling that I am trying to implement.
Video: GridView Issue
Grid Item Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="120dp"
android:orientation="vertical"
android:background="#drawable/card_background"
>
<TextView
android:id = "#+id/foo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="40dp"
style="#style/PrimaryBlueHeading"
/>
<View
android:id="#+id/list_uinderline"
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#android:color/white"/>
<Button
android:id="#+id/bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:background="#color/brand_color"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:text="#string/save"
android:textColor="#android:color/white" />
</LinearLayout>
GridView Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ProtocolListActivity">
<!-- android:paddingTop="?android:attr/actionBarSize" -->
<GridView
android:id="#+id/protocol_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:clipToPadding="false"
android:columnWidth="200dp"
android:numColumns="auto_fit"
android:verticalSpacing="50dp"
android:background="#drawable/backgound_potrait"
android:horizontalSpacing="50dp"
android:stretchMode="columnWidth"
android:scrollbarStyle="outsideOverlay"
android:gravity="center">
</GridView>
</RelativeLayout>

Android hide and show components

I am making a sqlite android application which is to list some data , show graphs , visit a web site by starting default browser(not in application by using webview) , send emails by using a form . I will have a couple of forms . So what I was thinking is that instead of using several activities and xml layouts I put it all in one xml layout and simply on button click show and hide components as it is done with javascript
These are my components for now ...
<ScrollView 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="432dp"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:text="ENTER COMPANY NAME " />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:ems="10">
<requestFocus />
</EditText>
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp"
android:entries="#array/country_arrays"
android:prompt="#string/country_prompt"
/>
<Spinner
android:id="#+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_below="#+id/spinner1"
android:entries="#array/limit_arrays"
android:prompt="#string/limit_prompt"
/>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/spinner2"
android:layout_centerHorizontal="true"
android:text="Hide" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/button1"
android:layout_centerHorizontal="true"
android:text="Show" />
</RelativeLayout>
</ScrollView>
Then I am to show or hide components by using for example
spinner1.setVisibility(View.VISIBLE);
spinner1.setVisibility(View.GONE);
This seams to be working fine , but I am getting a kind of low on space on my xml screen. How do I put more components in the bottom and make my View scroll down although I have put
<ScrollView 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">
on the top of my xml layout . And is this a good idea for a menu organisation ?

scrollview, tablelayout and linearlayout doesnt work together in android

I have a layout xml file which crashes and couldnt understand why. here is my xml, but I am not posting the entire xml.
<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="wrap_content"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:background="#drawable/gradient"
android:gravity="center">
.......
</TableRow>
</TableLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/sw_layout"
android:orientation="vertical">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#EEEEEE" >
<TableRow
android:id="#+id/tableRowDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
..........
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/btn_date"
android:layout_height="35dp"
android:padding="5dp"
android:drawableLeft="#drawable/calendar"
android:text="Tarih" />
<Button
android:id="#+id/btn_converter"
android:layout_height="35dp"
android:padding="5dp"
android:drawableLeft="#drawable/calendar"
android:text="Hesap" />
</LinearLayout>
</ScrollView>
</LinearLayout>
If I remove the last linearlayout. it works perfectly but I need to add button at the bottom of the screen. How can I add the buttons? I want to add the buttons and center them horizontally
Scrollview will allow only one child, so you have to kept that TableLayout and LinearLayout in one more separate layout as child of ScrollView.
Like this
<ScrollView
<LinearLayout
<TableLayout />
<LinearLayout />
</LinearLayout>
</ScrollView>

Categories

Resources