XML layout issue - java

I want to expand my XML layout as I have a number of buttons I need to put on one screen. I have added a scrollview under my textview and image view but cant seem to get the layout to expand? I'm also getting an XML error layout on my scrollview of:
error: Error parsing XML: mismatched tag
Here's my layout showing the expansion issue. Can anyone gibe me an Idea of what I'm doing wrong?:
Heres my XML - Im aware i have duplicate information. This is a test.:
<?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="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="84dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLink"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="0.91"
android:src="#drawable/menulist" />
<TextView
android:id="#+id/textView1"
android:layout_width="165dp"
android:layout_height="match_parent"
android:layout_weight="0.14"
android:gravity="center"
android:text="Menu"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="40sp" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/btnAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:drawableLeft="#drawable/addconmenu"
android:src="#drawable/addconmenu"
android:text="Contacts List" />
<Button
android:id="#+id/btnView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:drawableLeft="#drawable/todo"
android:src="#drawable/todo"
android:text="&apos;To Do&apos; List" />
<Button
android:id="#+id/btnEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:drawableLeft="#drawable/musicmenu"
android:src="#drawable/musicmenu"
android:text="Music List" />
<Button
android:id="#+id/btnEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:drawableLeft="#drawable/shoppingmenu"
android:src="#drawable/shoppingmenu"
android:text="Shopping List" />
<Button
android:id="#+id/btnEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:drawableLeft="#drawable/gymmenu"
android:src="#drawable/gymmenu"
android:text="Gym List" />
<Button
android:id="#+id/btnEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:drawableLeft="#drawable/appointmentmenu"
android:src="#drawable/appointmentmenu"
android:text="Appointment List" />
</LinearLayout>
</LinearLayout>
</ScrollView>

It looks like you should reverse the order of the last two lines of your layout. You are closing the ScrollView tag after closing the top-level LinearLayout tag.

The Linear Layout height inside of your ScrollView is wrapcontent if you make it match parent or fillparent it will solve your problem.

Related

Type error: Error parsing XML: junk after document element about_window.xml?

This is my code. All I did is that I changed the texts in the about window in all layouts file and I find this error in the xml file.
Multiple annotations found at this line:
error: Error parsing XML: junk after document element
The markup in the document following the root element must be well-
also in the src files the error is "R cannot be resolved to a variable". This is my the XML code:
version="1.0" encoding="utf-8"?>
<ScrollView android:orientation="vertical"
android:scrollbars="none"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"/>
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"
android:xmlns:android="http://schemas.android.com/apk/res/android"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6.0dip"
android:layout_marginTop="6.0dip"
android:text="xxxxxx"
android:textColor="#ffffffff"
android:textSize="14.0dip"
android:textStyle="bold" />
<TextView android:textSize="14.0dip" android:textStyle="bold" android:textColor="#ffffffff" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="6.0dip" android:layout_marginTop="10.0dip" android:text="#string/app_version_name" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6.0dip"
android:text="xxxxx"
android:textColor="#ffffffff"
android:textSize="14.0dip"
android:textStyle="bold" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6.0dip"
android:layout_marginTop="10.0dip"
android:text="xxxxxxx"
android:textColor="#ffffffff"
android:textSize="14.0dip" />
<TextView
android:id="#id/dev_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6.0dip"
android:layout_marginTop="20.0dip"
android:gravity="center_horizontal"
android:text="youss.boss1dev#gmail.com"
android:textColor="#2704fc"
android:textSize="14.0dip"
android:textStyle="bold" />
<LinearLayout android:gravity="center" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10.0dip"
android:xmlns:android="http://schemas.android.com/apk/res/android"/>
<Button
android:id="#id/close_btn"
android:layout_width="110.0dip"
android:layout_height="44.0dip"
android:layout_marginBottom="4.0dip"
android:layout_marginTop="4.0dip"
android:text="xxxx" />
</LinearLayout>
</LinearLayout>
</ScrollView>
This is the perfect Layout.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="none">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:xmlns="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6.0dip"
android:layout_marginTop="6.0dip"
android:text="xxxxxx"
android:textColor="#ffffffff"
android:textSize="14.0dip"
android:textStyle="bold"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6.0dip"
android:layout_marginTop="10.0dip"
android:text="app_version_name"
android:textColor="#ffffffff"
android:textSize="14.0dip"
android:textStyle="bold"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6.0dip"
android:text="xxxxx"
android:textColor="#ffffffff"
android:textSize="14.0dip"
android:textStyle="bold"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6.0dip"
android:layout_marginTop="10.0dip"
android:text="xxxxxxx"
android:textColor="#ffffffff"
android:textSize="14.0dip"/>
<TextView
android:id="#+id/dev_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6.0dip"
android:layout_marginTop="20.0dip"
android:gravity="center_horizontal"
android:text="youss.boss1dev#gmail.com"
android:textColor="#2704fc"
android:textSize="14.0dip"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10.0dip"
android:gravity="center"
android:orientation="vertical"
android:xmlns="http://schemas.android.com/apk/res/android">
<Button
android:id="#+id/close_btn"
android:layout_width="110.0dip"
android:layout_height="44.0dip"
android:layout_marginBottom="4.0dip"
android:layout_marginTop="4.0dip"
android:text="xxxx"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Your scroll view ends with a /> finishing the object, I think childrem will not have access to the tags android.
All your views are closed by itself (with "/>"). So your document doesnt have a root, only a list.
Also: Childs doesnt needs to declare xmlns again, such the second object:
android:xmlns:android="http://schemas.android.com/apk/res/android"
That also has a typo with android twice.
Also:
Do any text contains > or < ? It should be added into the strings.xml so those characters can appear
You have an error in LinearLayout:
android:xmlns:android="http://schemas.android.com/apk/res/android"
it should be:
xmlns:android="http://schemas.android.com/apk/res/android"
you typed twice android. Instead removing just android remove whole line you don't need it because you already have declaration in ScrollView Actually the problem is ScrollView can contain only one direct child and you have multiple. So you have to put all your xml code below ScrollView in one container either LinearLayout, RelativeLayout etc.

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">

Nested LinearLayouts don't work

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:

Why doesn't my linear layout match my parent height in listview?

I have the following code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/itemLayoutView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/list_view_layout_margin"
android:paddingRight="#dimen/list_view_layout_margin"
android:background="#color/yellow">
<LinearLayout
android:id="#+id/itemLinearLayoutView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/gameNameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/game_list_text_size" />
<TextView
android:id="#+id/gameCreationDateView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/gray"
android:textSize="#dimen/small_text_size"
android:textStyle="italic" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/red"
android:orientation="horizontal" >
<Button
android:id="#+id/infoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/info" />
<Button
android:id="#+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delete" />
</LinearLayout>
</RelativeLayout>
The LinearLayout with id itemLinearLayoutView is the main layout that wrap everything in a row of listview. The problem I am having is that the second linear layout child does not take the height of the parent linear layout with id itemLinearLayoutView. Any solutions? or Problem with the code?
Your problem lies here:
android:layout_height="wrap_content"
This needs to be changed to "match_parent" in the LinearLayout which you want to be the parent's size. Also, you said
the second linear layout child does not take the height of the parent linear layout
These two layouts are not parents and children to one another. The parent is your RelativeLayout and both of your LinearLayouts are equivalent children of that RelativeLayout. Maybe this will help you debug any further problems you encounter.
just change the layout height to match parent . problem will be resolved.
<LinearLayout
android:id="#+id/itemLinearLayoutView"
android:layout_width="match_parent"
// use match_parent instead of wrap_content
android:layout_height="match_parent"
android:orientation="vertical" >
the layout needs to be nested within the first linear layout to take the parameters of it, and the value of the layout height needs to be changed. Code as Follows.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/itemLayoutView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/list_view_layout_margin"
android:paddingRight="#dimen/list_view_layout_margin"
android:background="#color/yellow">
<LinearLayout
android:id="#+id/itemLinearLayoutView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/gameNameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/game_list_text_size" />
<TextView
android:id="#+id/gameCreationDateView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/gray"
android:textSize="#dimen/small_text_size"
android:textStyle="italic" />
<LinearLayout
android:id="#+id/LinearLayoutView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/red"
android:orientation="horizontal" >
<Button
android:id="#+id/infoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/info" />
<Button
android:id="#+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delete" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/itemLinearLayoutView"
android:layout_width="match_parent"
android:layout_height="match_parent" <!-- you should use match_parent here -->
android:orientation="vertical" >
// try this way i have used LinearLayout as parent rather than RelativeLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/itemLayoutView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="#dimen/list_view_layout_margin"
android:paddingRight="#dimen/list_view_layout_margin"
android:background="#color/yellow">
<LinearLayout
android:id="#+id/itemLinearLayoutView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/gameNameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="#dimen/game_list_text_size" />
<TextView
android:id="#+id/gameCreationDateView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/gray"
android:textSize="#dimen/small_text_size"
android:textStyle="italic" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayoutView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="right"
android:background="#color/red"
android:orientation="horizontal" >
<Button
android:id="#+id/infoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/info" />
<Button
android:id="#+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delete" />
</LinearLayout>
</LinearLayout>

Unable to make all UI components appear in RelativeLayout

I want a RelativeLayout based android UI that looks like the below mock graphic:
Below is my layout xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayoutForPreview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- surface view that contains camera preview , and seats above #+id/linearLayoutToolbar -->
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- LinearLayout that contains toolbar that is divided into 3 sections horizontally -->
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/surfaceViewBarcodeScanner"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_left" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_center_toolbar" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
</RelativeLayout>
I used Eclipse GUI palette and my own editing , however the output was not what I expected, the SurfaceView seems to covering all the screen, the LinearLayout at the bottom does not appear.
Snapshot of my current result on Galaxy S3 device:
Any help will be appreciated, Thanks.
Could you please try out to modify your layout as the follows:
Define your SurfaceView and set it's layout_above value to the ID of the linear layout made in the previous step. Set the layout_alignParentTop to true.
Define your bottom linear layout and set the layout_alignParentBottom to true.
Smart code snippet with only the important parts:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android">
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#+id/linearLayoutToolbar" />
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
I hope this will solve your problem.
you can use Linearlayout instead of Realtive Layout
<?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" >
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<!-- inside elements -->
</LinearLayout>
</LinearLayout>
else you should use android:layout_above="#+id/linearLayoutToolbar" to your surfaceview
and remove android:layout_below attribute and add android:layout_alignParentBottom="true" to your toolbar view.
// try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayoutForPreview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent">
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:gravity="center"
android:layout_weight="1">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_left" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:gravity="center"
android:layout_weight="2">
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_center_toolbar" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:gravity="center"
android:layout_weight="1">
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Categories

Resources