Alternating Textview and Imageview inside a Scrollview - android

I'm trying to have an alternating text and image in my scrollview. There are no errors on the code, however when I try to run the application. Its force closing. I'm new to android studio. How can I fix this? I tried to search answers here but I cant seem to find the solution that I'm looking for.
Here is my code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity ="center"
android:fillViewport="true"
android:layout_alignParentStart="true"
android:layout_marginTop="0dp"
android:id="#+id/scrollView">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#000"
android:textColorLink="#android:color/black"
android:textSize="18sp"
android:text="hello"/>
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/cheese_1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#000"
android:textColorLink="#android:color/black"
android:textSize="18sp"
android:text="hi" />
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/cheese_2"/>
</ScrollView>
</LinearLayout>

instead use a Listview or Recyclerview and have a custom Adapter to show image and text alternatively. That would be lot better and controllable.
if you still want to use only scrollview you can have only one direct child to scrollview.Add a linear layout as a child of scrollview and all image and textviews as children to that linearlayout as follows
<ScrollView ..>
<LinearLayout ..>
<TextView ../>
<ImageView ../>
<TextView ../>
</LinearLayout>
</ScrollView>

Now it work
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity ="center"
android:fillViewport="true"
android:layout_alignParentStart="true"
android:layout_marginTop="0dp"
android:id="#+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#000"
android:textColorLink="#android:color/black"
android:textSize="18sp"
android:text="hello"/>
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/cheese_1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#000"
android:textColorLink="#android:color/black"
android:textSize="18sp"
android:text="hi"/>
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/cheese_2"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

Scrollview can contains only one child in it. so put you imageViews and TextViews in LinearLayout and then put LinearLayout in ScrollView.

You have include too many direct children in the scroll view. Scroll view can handle only one child at time so m you have to wrap your all other views under only one view.
so your xml will look like this now
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity ="center"
android:fillViewport="true"
android:layout_alignParentStart="true"
android:layout_marginTop="0dp"
android:id="#+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#000"
android:textColorLink="#android:color/black"
android:textSize="18sp"
android:text="hello"/>
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/cheese_1"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#000"
android:textColorLink="#android:color/black"
android:textSize="18sp"
android:text="hi" />
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/cheese_2"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
This should work now.

Related

Adding movie overview TextView in xml inside a Scrollbar

I have the following xml. Basically I want to display the movie overview below the Layout whose id is equals to layoutOne.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarStyle="outsideOverlay">
<LinearLayout
android:id="#+id/layoutOne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:padding="16dp"
android:background="#color/primary"
>
<ImageView
android:id="#+id/movie_image"
android:layout_width="160dp"
android:layout_height="240dp"
android:scaleType="fitXY"
android:layout_gravity="center_vertical"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:padding="16dp"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content">
<TextView
android:id="#+id/movie_title"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
/>
<TextView
android:layout_below="#+id/movie_title"
android:layout_centerHorizontal="true"
android:id="#+id/movie_rating"
android:text="9/10"
android:textSize="24sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_below="#+id/movie_rating"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_marginTop="13dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/ic_menu_my_calendar"/>
<TextView
android:layout_below="#+id/movie_rating"
android:layout_centerHorizontal="true"
android:id="#+id/movie_date"
android:text="2017-10-9"
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dp"
/>
</LinearLayout>
</RelativeLayout>
<TextView
android:id="#+id/title_overview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Great movie" />
</LinearLayout>
</ScrollView>
Here is what I get.
I want the sample text Great movie to be below that light pink layout. The tricky part here is that Scrollbar view allow only one child view. Any ideas?
Thanks,
Theo.
The Constraint of the RelativeLayout should fit the whole page. If you want to use ScrollView you should add the RelativeLayout to the ScrollView too.
Hence it would be like this :
<LinearLayout
android:id="#+id/layoutOne"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:padding="16dp"
android:background="#color/primary"
>
Later you can use the following to adjust the image:
<LinearLayout
android:layout_marginBottom="439dp"
android:layout_marginEnd="156dp"
android:layout_marginStart="156dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
>

wrap_content leaving extra white space at bottom of screen for ViewPager

enter image description here
Wrap_content inside 2nd linearlayout leaving the extra white space at bottom of screen but if give hardcoded value it's working fine. any issue with wrap_content ? Here I am using this .xml on viewPager anyone have idea about this issue.
<?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:background="#drawable/white_noround">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/canceledPesananTgl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ABCDEFGHI"
android:textSize="14sp"
android:padding="10dp"
android:textStyle="bold"
android:textColor="#999999"
android:fontFamily="sans-serif-light"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="-15dp"
android:text="29 JAN 2016"
android:textSize="14sp"
android:padding="10dp"
android:textStyle="bold"
android:textColor="#999999"
android:id="#+id/canceledDate"
android:fontFamily="sans-serif-light"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical"
android:visibility="visible"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/image_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".9"
android:orientation="vertical"
android:layout_marginLeft="10dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="#+id/canceled_dummuyImage1"
android:background="#drawable/imageview_border"
android:layout_gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:src="#drawable/empty_photo"/>
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:id="#+id/canceled_dummuyImage2"
android:background="#drawable/imageview_border"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:src="#drawable/empty_photo"/>
<LinearLayout
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_marginTop="20dp"
android:background="#drawable/imageview_border">
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:id="#+id/canceledImage"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:src="#drawable/empty_photo"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight=".4"
android:paddingBottom="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SONY Memory Card Playstation 2"
android:textSize="16sp"
android:id="#+id/productName"
android:fontFamily="sans-serif-light"
android:textColor="#333333"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:id="#+id/productStatus"
android:textSize="14dp"
android:text="Dalam pengiriman"
android:textStyle="normal"
android:fontFamily="sans-serif"
android:textColor="#f7931e"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
The Problem is here. see this Parent LinearLayout.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight=".4"
android:paddingBottom="10dp">
In this You have used android:paddingBottom="10dp" so the child' element work fine but The Extra white Space is for it's parent layout to Solve your problem remove android:paddingBottom="10dp" line.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical"
android:visibility="visible"
>
in the above linear layout instead of layout_height as 150dp try giving wrap_content
What I was doing with above .xml was to populate list of items using listView on ViewPager. So the above .xml is listItem .xml so we should always go with below code.This line worked for me android:layout_height="wrap_content".
<?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="wrap_content"
android:background="#drawable/white_noround"/>

How to set ImageView and the textView in a single line inside a LinearLayout

I'm struggling to set an imageView and a textView in a single line inside LinearLayout. I tried with different ways but still I couldn't find a proper solution. Here is the code I used:
<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="40dp"
android:clickable="true"
android:orientation="vertical"
android:paddingLeft="40dp"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/icon_image"
android:layout_width="30sp"
android:layout_height="30sp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:layout_gravity="bottom"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="14sp"
android:textStyle="bold" >
</TextView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/black" />
</LinearLayout>
This is how it is appear :
What should I have to do to make correct this?
Its inside of a LinearLayout with a vertical orientation so naturally everything is stacked "vertically". Wrap them in a LinearLayout with a horizontal orientation
<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="40dp"
android:clickable="true"
android:orientation="vertical"
android:paddingLeft="40dp"
tools:context=".MainActivity" >
<LinearLayout
.../>
<ImageView
android:id="#+id/icon_image"
android:layout_width="30sp"
android:layout_height="30sp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:layout_gravity="bottom"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="14sp"
android:textStyle="bold" >
</TextView>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/black" />
</LinearLayout>
By default, LinearLayout has a horizontal orientation so no need to supply that property in the child LinearLayout which wraps the two Views.
Use android:layout_gravity="center_vertical" for your textview
I suggest to use a RelativeLayout. That way you can add more items vertically as well.
You need to change the linearylayout's orientation. Just change android:orientation="vertical"
to
android:orientation="horizontal"
You can try enclosing your ImageViews and TextViews inside a TableLayout
<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="40dp"
android:clickable="true"
android:orientation="vertical"
android:paddingLeft="40dp"
tools:context=".MainActivity" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow>
<ImageView
android:id="#+id/icon_image"
android:layout_width="30sp"
android:layout_height="30sp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:layout_gravity="bottom"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="14sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/black" />

Text overlay over imageview in android

I am trying to have textviews overlay over imageviews. Something like this
Can someone help me with the code.
Wrap a TextView and ImageView into FrameLayout, put the TextView in FrameLayout after ImageView. Then, wrap the FrameLayout into RelativeLayout OR LinearLayout. Make some position setup (as per the needs).
<RelativeLayout>
<FrameLayout>
<ImageView />
<TextView />
</FrameLayout>
</RelativeLayout>
You can create a frame layout and within the frame layout keep an imageview and a linearlayout(with a translucent background and a textview).
The translucent color can be placed in the colors file as : #80000000
Here is a snippet :)
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:foregroundGravity="bottom"
android:orientation="vertical" >
<ImageView
android:id="#+id/ivFullScreenAd"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="8dp"
android:src="#drawable/home_page_ad" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/translucent"
android:orientation="vertical" >
<TextView
android:id="#+id/detailTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:paddingLeft="10dip"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Please swipe up"
android:textColor="#color/white"
android:textIsSelectable="true"
android:textSize="20sp" />
</LinearLayout>
</FrameLayout>
I had the same problem and solved it using a custom gridView. You must apply this in getView.
Custom gridView XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_practitioner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/item_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:contentDescription="#string/contentDescriptionContent"
/>
<LinearLayout
android:id="#+id/layout_login"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center"
android:background="#CC515116"
android:visibility="gone"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:text="#string/text_enter_pass_password"
android:paddingBottom="7dp"
android:textSize="20sp"
/>
<EditText
android:id="#+id/edit_practitioner_pin"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="center"
android:background="#drawable/edittext_shape"
android:ems="6"
android:gravity="center"
android:inputType="numberPassword"
android:maxLength="4"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:visibility="visible"
/>
<Button
android:id="#+id/pract_button"
android:layout_width="70dp"
android:layout_height="30dp"
android:background="#drawable/buton_shape"
android:layout_marginBottom="35dp"
android:text="#string/btn_ok"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom"
android:background="#bbffffff"
android:focusable="false"
android:focusableInTouchMode="false" >
<TextView android:id="#+id/item_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:textColor="#color/text_black"
android:gravity="bottom|center"
android:textSize="20sp"
android:textAllCaps="true"
android:paddingBottom="0dp"
/>
<TextView
android:id="#+id/text_pratiotioner_group_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#color/sub_title_color"
android:visibility="visible"
android:gravity="bottom|center"
android:textAllCaps="true"
/>
</LinearLayout>
</FrameLayout>
Though an old question but should incase anyone is interested in the card view version of this question here you go...
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="5dp"
app:cardElevation="5dp"
android:layout_weight="0.5"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
android:clickable="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical"
android:layout_centerInParent="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:background="#89969F">
<ImageView
android:id="#+id/iv_overlay"
android:layout_width="196dp"
android:layout_height="196dp"
android:clickable="true"
android:src="#drawable/your_image"
android:layout_centerInParent="true" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#80000000"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="22sp"
android:textStyle="bold"
android:gravity="center_vertical"
android:text="Settings"
android:textColor="#color/white"
android:layout_gravity="center"
android:layout_alignParentTop="false"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:padding="8dp" />
</LinearLayout>
</FrameLayout>
</android.support.v7.widget.CardView>
Please modify the layout accordingly, If you want to accommodate the images on an imageview only, then you can drop the below layout in a relative one including an imageview too.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/your_image"
android:orientation="vertical" >
<TextView
android:id="#+id/bottom_textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
<!-- layout_gravity="supply accordingly" -->
android:gravity="center"/>
</LinearLayout>

Linearlayout for different screen sizes

I have a linearLayout which is surrounded by a scrollView in order to make it for smaller screens scrollable. In the linear layout I have 3 childs which are also linearlayout.
This is working fine. But I also want to support larger screens. At the moment I get with a larger screen space left on the bottom of the screen. I want to have the buttons (navigation bar) be always at the bottom. for larger screens (height) I would like to add at the top of the screen an empty view which fills out the space that is more provided by the larger screen.
How can I achieve that? i tried a lot with weight attribute but didnt get it working.
Here the layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#8db9f6"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#8db9f6">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_marginTop="8dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="test"
android:id="#+id/test"
android:paddingLeft="10dp"
android:textStyle="bold"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<View
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"/>
<ImageButton
android:id="#+id/btnName"
android:scaleType="center"
android:layout_width="60dp"
android:layout_height="48dp"
android:src="#android:drawable/ic_menu_edit">
</ImageButton>
</LinearLayout>
<EditText
android:id="#+id/edittest"
android:editable="false"
android:hint="#string/test"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</EditText>
<TextView
android:text="#string/optionalText"
android:id="#+id/test1"
android:paddingLeft="10dp"
android:textSize="12dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView
android:id="#+id/space"
android:layout_width="fill_parent"
android:layout_marginTop="4dp"
android:layout_height="3sp"
android:background="#333142">
</TextView>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="TEST TESt"
android:id="#+id/test2"
android:paddingLeft="10dp"
android:layout_marginTop="5dp"
android:textStyle="bold"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<View
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="#+id/progressbar"/>
<ImageButton
android:id="#+id/btnPicture"
android:scaleType="center"
android:layout_width="60dp"
android:layout_height="48dp"
android:src="#android:drawable/ic_menu_edit">
</ImageButton>
</LinearLayout>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:background="#ffffff"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="150dip">
<ImageView
android:id="#+id/test3"
android:layout_width="400dip"
android:layout_height="150dip"
android:layout_gravity="center"
android:scaleType="fitCenter"
android:src="#drawable/test1"/>
<TextView
android:id="#+id/text"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8dp"
android:text="test test"/>
</FrameLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:layout_marginTop="3dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/scaleMinus"
android:textSize="14dp"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:text="#string/zoomOut"/>
<Button
android:id="#+id/scalePlus"
android:textSize="14dp"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:text="#string/zoomIn"/>
</LinearLayout>
<TextView
android:id="#+id/balken"
android:layout_width="fill_parent"
android:layout_marginTop="4dp"
android:layout_height="3sp"
android:background="#333142">
</TextView>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_marginTop="5dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="test test"
android:id="#+id/test3"
android:paddingLeft="10dp"
android:textStyle="bold"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<View
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"/>
<EditText
android:id="#+id/test4"
android:editable="false"
android:layout_width="100dp"
android:layout_height="wrap_content">
</EditText>
<TextView
android:text="test"
android:id="#+id/mtest4"
android:paddingLeft="10dp"
android:textStyle="bold"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<View
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"/>
<ImageButton
android:id="#+id/test5"
android:scaleType="center"
android:layout_width="60dp"
android:layout_height="48dp"
android:src="#android:drawable/ic_menu_edit">
</ImageButton>
</LinearLayout>
<TextView
android:id="#+id/balken"
android:layout_width="fill_parent"
android:layout_marginTop="4dp"
android:layout_height="3sp"
android:background="#333142">
</TextView>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:background="#000000"
android:paddingTop="5dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/save"
android:textSize="18dp"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:text="#string/save"/>
<Button
android:id="#+id/cancel"
android:textSize="18dp"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:text="#string/abort"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Wrap the entire layout in a Relative Layout. Use a relative layout as your root element and set the Linear Layout containing your buttons to layout_alignParentBottom="true" and the ScrollView set to layout_alignParentTop="true".
The LinearLayout containing the buttons and the ScrollView should be direct children of the RelativeLayout.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout <-- containing the layout minus the buttons
android:id="#+id/SV"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<The Rest Of The Layout>
</LinearLayout>
<LinearLayout
android:id="#+id/LLButtons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Buttons>
</LinearLayout>
</ScrollView>
If you want the buttons to be always at the bottom of the screen alignParentBottom. If you want the buttons to always be at the bottom of the scrollview alignBelow="#id/SV"
android:layout_height="wrap_content" in your inner LinearLayout is your trouble here, changing it to 'fill_parent' should help. In general, you may want to use hierarchyviewer to help troubleshoot layout issues like this.

Categories

Resources