Nested LinearLayouts don't work - java

I have a root vertical LinearLayout which contains few TextViews and others LinearLayout with default orientation (horizontal). However, from some reason, none of these nested LinearLayouts is displayed - I have a hunch that they are overflowing the screen width but I am sure how it is possible because I have set the parents orientation to vertical. Here is my code
<?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:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/infoHeadline1"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_marginBottom="15dp"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/infoText1"/>
<!-- Elements are shown only up to infoText1 -->
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/infoText2"
android:textStyle="bold" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/infoText3"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/infoText4" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/infoText5"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
I am trying to layout the text into something similar to this page. The reason for first nester LinearLayout is that I need to make text in the middle of the paragraph bold.
So what is the correct way for nesting layouts in Android?

You don't need to include:
xmlns:android="http://schemas.android.com/apk/res/android"
in any of the nested LinearLayouts. Only the first. Perhaps that is causing your nested layouts to act strangely.
Would have commented if I had enough reputation...

Observation::
The code xmlns:android="http://schemas.android.com/apk/res/android"
must only be present in the root view Layout
Instead you have multiple times defined in your code
Change your code to as below::
<?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:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginTop="10dp"
android:text="infoHeadline1"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="infoText1" />
<!-- Elements are shown only up to infoText1 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="infoText2"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="infoText3" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="infoText4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="infoText5"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
Snapshot:

Related

How to set up the layout of the alignment?

I don't know how to set up the layout of the alignment? Maybe this is a simple question but i am no idea,And I'm a new Android developer.Please provide the way of thinking,Thank you!
This is my page to display hierarchical relationship.
This page is made up of two layout, parent and child:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/table_cell_bg_color">
<TextView
android:id="#+id/parent_task_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="40px"
android:paddingTop="6px"
android:paddingBottom="6px"
android:textSize="18sp"
android:textColor="#2B2B2B"
android:text="No data"/>
<ImageView
android:id="#+id/arrow_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:src="#drawable/ram_arrow_close"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/table_cell_bg_color" >
<TextView
android:id="#+id/child_task_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:paddingLeft="60px"
android:paddingTop="10px"
android:paddingBottom="10px"
android:textSize="18sp"
android:textColor="#2B2B2B"
android:text="No Data" />
<TextView
android:id="#+id/child_task_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:paddingLeft="60px"
android:paddingTop="10px"
android:paddingBottom="10px"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#color/text_blue"
android:text="No Data"/>
<ImageView
android:id="#+id/arrow_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="0.3"
android:src="#drawable/ram_arrow_icon"/>
</LinearLayout>
Use this Code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/table_cell_bg_color">
<TextView
android:id="#+id/child_task_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#2B2B2B"
android:text="No Data" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/arrow_layout"
android:layout_toLeftOf="#+id/arrow_layout"
android:layout_toStartOf="#+id/arrow_layout"
android:paddingRight="10dp">
<TextView
android:id="#+id/child_task_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#color/text_blue"
android:text="No Data"/>
</LinearLayout>
<LinearLayout
android:id="#+id/arrow_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:paddingRight="10dp">
<ImageView
android:id="#+id/arrow_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ram_arrow_icon"/>
</LinearLayout>
I thing you are using list view or recyclerview so you should use this view to repeat the content based on array size
Possible solutions for you.
Table Layout
Relative Layout
You can use with layout
android:gravity=""
and
android:layout_gravity=""

linear layout not filling parent down the remaining part of the screen in a scrollview

I am designing a layout for an activity where some contents like Textview, spinner and buttons are arranged in the upper part of the screen. I want to position image view to the bottom of the screen with a match_parent attribute to fill to the remaining bottom of the screen and it has become a challenge to me as the image view is filling to the bottom of the remaining part of the screen. This is the entire layout of the upper section/part of the screen
<?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="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:layout_width="fill_parent"
android:background="#drawable/xxxVal"
android:padding="10dp"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/dataVaues"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="25sp"
android:gravity="center_horizontal"
android:textColor="#000"
/>
<Spinner
android:id="#+id/spinBundle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6sp"
android:textColor="#000"
android:prompt="#string/_prompt" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#000"
android:text="Plan" />
<TextView
android:id="#+id/bundle"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textSize="30sp"
android:textColor="#000"/>
<!-- android:inputType="phone" -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="#000"
android:text="PValue:" />
<TextView
android:id="#+id/value"
android:inputType="value"
android:layout_height="wrap_content"
android:textSize="30sp"
android:layout_width="match_parent"
android:textColor="#000"/>
<TextView
android:id="#+id/validValue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Valid:"
android:textColor="#000000" />
<TextView
android:id="#+id/valid"
android:inputType="valid"
android:layout_height="wrap_content"
android:textSize="30sp"
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:textColor="#ff0000"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical" >
<Button
android:id="#+id/proceed"
android:text="Proceed"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textColor="#000"/>
<Button
android:id="#+id/data"
android:text="Check"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginTop="10dp"
android:textColor="#000"/>
</LinearLayout>
this is remaining part of the layout with a view flipper for an image that I want it to fit down to the remaining part of the screen but its not fitting as it shrinks up
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="3dp"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ViewFlipper
android:id="#+id/flipper1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:flipInterval="5000"
android:inAnimation="#anim/slide_in_right"
android:outAnimation="#anim/slide_out_left" >
</ViewFlipper>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
please kindly assist!
Try adding the imageview to the Viewflipper like so:
<ViewFlipper
android:id="#+id/simpleViewFlipper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src=IMAGE />
</ ViewFlipper >
Having said that you might find some issues regarding swiping when using a viewflipper inside a scrollview

Android Linear Layout is not visible

I have a problem that i want to show the linear layout in parent after i check the condition. I want to show linear layout android:id="#+id/linearIndex" in the body of parent layout. Here the code.
The Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:id="#+id/lstep3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
android:id="#+id/linearIndex"> //THE LAYOUT I WANT TO SHOW
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:text="Jumlah Kasus Tambahan di Lokasi PE"
android:textColor="#color/teal"
/>
<!-- daftar gejala yang dimasukkan-->
<ListView
android:layout_width="match_parent"
android:layout_height="120dp"
android:id="#+id/listvievadvance2"
android:layout_marginTop="10dp"></ListView>
<!-- form gejala-->
<!-- form data gejala-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="15dp"
android:background="#color/accent_501">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pilih Lokasi"
android:textStyle="bold"/>
<Spinner
android:id="#+id/lokasiPilih"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
/>
<TextView
android:id="#+id/txtLocLain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Lokasi lain"
android:textStyle="bold"
/>
<EditText
android:layout_width="match_parent"
android:layout_marginTop="7dp"
android:hint="Lokasi lain"
android:layout_height="wrap_content"
android:id="#+id/lokasiLain"
android:theme="#style/TextLabel"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Tanggal PE"
android:textStyle="bold"
/>
<EditText
android:layout_width="match_parent"
android:layout_marginTop="7dp"
android:hint="Tanggal PE"
android:layout_height="wrap_content"
android:id="#+id/tglPE"
android:editable="false"
android:theme="#style/TextLabel"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jumlah Kasus tambahan"
android:textStyle="bold"
/>
<EditText
android:layout_width="match_parent"
android:layout_marginTop="7dp"
android:hint="Masukan jumlah kasus"
android:layout_height="wrap_content"
android:id="#+id/jmlKasusTambah"
android:theme="#style/TextLabel"
/>
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/btambahLokasi"
android:text="Tambah"
android:textColor="#fff"
android:layout_marginTop="10dp"
android:background="#color/teal"
/>
</LinearLayout>
</LinearLayout>
And the java file
Function that show visibility of layout
private void checkIndexOrNot(){
Log.i("Value :", String.valueOf(campak.getSurveilans().getStatusKasus()));
if(Integer.parseInt(campak.getSurveilans().getStatusKasus()) == 1) {
linearIndex.setVisibility(View.VISIBLE);
} else {
linearIndex.setVisibility(View.GONE);
}
}
I know it's look like no problem, but the function that show visibility of layout does not work. The layout does not show after check condition. The logic of the condition that check from DB is working fine, no error.
I put the checkIndexOrNot() in onCreate() function.
Thank you in advance.
Your parent layout of linearIndex has gone as default property mean it will not be visible. To show children views, the parent layout must be visible. So either set both layouts to visible programatically or just remove the visibility="gone" from lstep3
Just remove android:visibility="gone" from root layout.
Change this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:id="#+id/lstep3">
To this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lstep3">

How to align title,description and url in equal space

Here is a screenshot of layout as it currently appears on my screen:
Here is the xml code snippet for the layout:
<?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">
<ImageView
android:id="#+id/icon"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_alignParentRight="true"
android:layout_marginRight="-10dp" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:height="20dp"
android:fontFamily="Cabin-Regular"
android:paddingLeft="10dp"
android:textColor="#E35B5B"
android:textSize="14dp" />
<TextView
android:id="#+id/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:height="44dp"
android:fontFamily="Cabin-Regular"
android:paddingLeft="10dp"
android:paddingRight="100dp"
android:textColor="#2D2D2D"
android:textSize="16dp" />
<TextView
android:id="#+id/url_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_marginTop="50dp"
android:height="15dp"
android:paddingLeft="10dp"
android:paddingRight="80dp"
android:textColor="#BDBDBD"
android:textSize="10dp" />
</RelativeLayout>
Just want to have the three textviews properly aligned and have equal space among each other.
Here is your layout,
<?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">
<ImageView
android:id="#+id/icon"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_alignParentRight="true"
android:layout_marginRight="-10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="110dp"
android:layout_toLeftOf="#+id/icon"
android:orientation="vertical"
android:weightSum="3">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fontFamily="Cabin-Regular"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Title"
android:textColor="#E35B5B"
android:textSize="14dp" />
<TextView
android:id="#+id/desc"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#+id/title"
android:layout_weight="1"
android:fontFamily="Cabin-Regular"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Description"
android:textColor="#2D2D2D"
android:textSize="16dp" />
<TextView
android:id="#+id/url_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#+id/title"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="URL"
android:textColor="#BDBDBD"
android:textSize="10dp" />
</LinearLayout>
</RelativeLayout>
Pawan Thakur Use the same paddingLeft for all test and layoutBelow like below
<TextView
android:id="#+id/url_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/desc"
android:height="15dp"
android:paddingRight="80dp"
android:paddingLeft="10dp"
android:text="url"
android:textColor="#BDBDBD"
android:textSize="10dp" />
here is the code. Try maximum to use LinearLayout instead of Relative. Relative layout are used in cases where 2 or more elements have to be overlapped each other. Don't include every elements in a single layout. Divide your design into different sections, and use LinearLayout for each section and within each section, include elements belonging to that section.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".25"
android:orientation="vertical"
>
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#E35B5B"
android:fontFamily="Cabin-Regular"
android:textSize="14dp"
android:layout_weight="0.33"
android:singleLine="true"
android:ellipsize="end"
android:gravity="center|left"
android:paddingLeft="10dp"
android:text="Google"
/>
<TextView
android:id="#+id/desc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#2D2D2D"
android:fontFamily="Cabin-Regular"
android:textSize="16dp"
android:layout_weight="0.33"
android:singleLine="true"
android:ellipsize="end"
android:gravity="center|left"
android:paddingLeft="10dp"
android:text="Google is a Search engine"
/>
<TextView
android:id="#+id/url_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/title"
android:textColor="#BDBDBD"
android:textSize="10dp"
android:layout_weight="0.33"
android:singleLine="true"
android:ellipsize="end"
android:gravity="center|left"
android:paddingLeft="10dp"
android:text="http://www.google.com"
/>
</LinearLayout>
<LinearLayout
android:layout_width="110dp"
android:layout_height="110dp"
>
<ImageView
android:id="#+id/icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</LinearLayout>
u can use a android:weight="" to child of relative layout
Create LinearLayout for title, description and url with vertical orientation and weightsum=3 in Layout and for each of them use width=wrap_content, height=0dp, weight=1.
Okey.. First remove android:height from each TextView and in last TextView you have set android:layout_marginTop="50 remove it.
Tip : Use LinearLayout if your want to show your all view vertically or horizontally. if you want to use RelativeLayout make sure you give margin and padding properly so they look good.
Use Linear layout as parent with weightsum and equally distribute weight amongs the child layouts. ex : If android:weightsum = "3" for parent then android:layout_weight = "1" for each child layout(if you want equal space for each one of the 3 child).
ps: dont forget to mention orientation for Linearlayout.
Just Check this,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1
android:padding="10dp"
android:orientation="vertical">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#E35B5B"
android:fontFamily="Cabin-Regular"
android:textSize="14dp"
android:text="Google"/>
<TextView
android:id="#+id/desc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#2D2D2D"
android:fontFamily="Cabin-Regular"
android:textSize="16dp"
android:margin_top="5dp"
android:text="Google is a Search engine"/>
<TextView
android:id="#+id/url_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#BDBDBD"
android:textSize="10dp"
android:margin_top="5dp"
android:text="http://www.google.com"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"/>
</LinearLayout>
</LinearLayout>

How to add a scroll view to an entire activity?

I tried adding a scroll view around everything on an activity layout but it gave me an error saying it can only be placed around one thing.
My activity, has a title textview then an image, then a description text view, and you can not read the whole description because its to long and goes below the edge of my screen. How can I make the whoel thing scrollable?
My xml looks like this:
<?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" >
<TextView
android:id="#+id/beerTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="40sp"
android:textStyle = "bold"
>
</TextView>
<ImageView android:id="#+id/image"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_margin="10dip"/>
<Button
android:id="#+id/buttonBrewery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<Button
android:id="#+id/buttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/beerDEscriptionTitle"
android:textStyle = "bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="20sp"
android:text="Description"
></TextView>
<TextView
android:id="#+id/beerDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="15sp"
></TextView>
</LinearLayout>
Try this:
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- TextView and other stuff -->
</LinearLayout>
</ScrollView>
Wrap the LinearLayout (height is wrap_content) with SrollView (height is fill_parent).
The "one thing" is your LinearLayout. Just wrap that in a ScrollView and you will encapsulate the layout for the entire activity.
Additionally, if you want to wrap just one elemtnet in a ScrollView all you have to do is put that element in it's own layout, like a linear or relative layout, and then that becomes the one element of your ScrollView
just use this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/beerTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="40sp"
android:textStyle = "bold"
>
</TextView>
<ImageView android:id="#+id/image"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_margin="10dip"/>
<Button
android:id="#+id/buttonBrewery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<Button
android:id="#+id/buttonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/beerDEscriptionTitle"
android:textStyle = "bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="20sp"
android:text="Description"
></TextView>
<TextView
android:id="#+id/beerDescription"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:textSize="15sp"
></TextView>
</LinearLayout>
</ScrollView>

Categories

Resources