LinearLayout and TextView doesn't show properly - java

I'm trying to create a new LinearLayout and now i have added a text and a background and now the background appears and still not full as it seems in the graphical they both show up in the graphical layout
example here:
https://www.dropbox.com/s/k58uznho9pu5qky/Untitled1.png
and when i test it out in a emulator which is real device the background isn't showing probably with some white space down and the text doesn't even appear
example here:
https://www.dropbox.com/s/q9e45sunbsesrd1/uniteled3.png
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="vertical"
tools:context=".SecondActivity" >
<LinearLayout
android:id="#+id/linearlayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/images"
android:gravity="center|right"
android:orientation="vertical" >
<TextView
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="10sp"
android:text="testing ytestifnfndfijdfhffdkjdfkjfdjkj"
android:textSize="25sp" />
</LinearLayout>
</ScrollView>

How does this fit your needs? If you plan to add more content, then the root component can be ScrollView with the background. But with only one TextView, there should be no need for ScrollView unless the text is huge.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/images"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SecondActivity" >
<TextView
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="testing ytestifnfndfijdfhffdkjdfkjfdjkj"
android:textSize="25sp" />
</LinearLayout >

to fill whole screen with your layout use match_parent for layout_height and layout_width
<LinearLayout
android:id="#+id/linearlayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/images"
android:gravity="center|right"
android:orientation="vertical" >

Related

Set Layout Edge Round

I am trying to make my layout edge round so I am using card view and
also trying to define my own XML with rounded settings and thus link the XML to the background of the Linear Layout but that is also not working.
I have also attached the picture What I am getting from there but I want White rectangular edges to be gone-
..enter image description here
app:cardCornerRadius="9dp"
but here I am getting rectangular background and I don't understand where that white background come from. So, here's my code-
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="9dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout 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:orientation="vertical" android:layout_width="match_parent"
android:id="#+id/relative_layout"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="46dp"
android:id="#+id/toolbar"
android:background="#color/fab_background">
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_marginBottom="10dp"
android:layout_width="50dp"
android:layout_height="40dp"
android:src="#drawable/expense"
android:id="#+id/expense_image"/>
<EditText
android:layout_marginLeft="29dp"
android:layout_width="match_parent"
android:layout_toRightOf="#id/expense_image"
android:layout_height="40dp"
android:hint="#string/expense"
android:id="#+id/expense"
android:inputType="number"/>
<ImageView
android:layout_width="50dp"
android:layout_height="40dp"
android:src="#drawable/note"
android:id="#+id/note_image"
android:layout_marginTop="60dp"/>
<EditText
android:layout_marginLeft="29dp"
android:layout_marginTop="20dp"
android:layout_toRightOf="#id/note_image"
android:layout_below="#id/expense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/add_note"
android:id="#+id/add_note"/>
</RelativeLayout>
<Button
android:layout_marginTop="20dp"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_margin="16dp"
android:id="#+id/putOn"
android:layout_below="#id/add_note"
android:text="#string/put_on"
android:background="#android:color/darker_gray"/>
</LinearLayout>
</android.support.v7.widget.CardView>
If you are using CardView as a root for for your alert dialog then do as follows . Let me know if it works .
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_gravity="center"
card_view:cardBackgroundColor="#android:color/transparent"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical">
// Your layout goes here
</LinearLayout>
</android.support.v7.widget.CardView>
If still not work then use card_view:cardPreventCornerOverlap attribute in cardview .
Whereas you can use android.support.v7.app.AppCompatDialog for same appearance without any CardView.

Android scrollable layout - views not visible on orientation change

My XML scrollable layout (work in progress) looks like this:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_height="wrap_content"
android:layout_width="match_parent"
>
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/tvStatus"
android:text="0 SMS found"
android:textSize="15sp"
android:layout_width="120dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnExport"
android:layout_width="88dp"
android:layout_height="wrap_content"
android:text="Export"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
When load app on testing device in portrait mode, all views are presented and visible:
portrait mode
When device orientation is changed to horizontal, only listview part of layout is visible (?!?):
landscape mode
Does anybody has clue on what possibly is going on here? Thanks.
This is the layout you need:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/tvStatus"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="0 SMS found"
android:textSize="15sp"/>
<Button
android:id="#+id/btnExport"
android:layout_width="88dp"
android:layout_height="wrap_content"
android:text="Export"
/>
</LinearLayout>
</LinearLayout>
You can also view how will your layout be in landscape mode while constructing it:
it seems you are missing closing tag of scroll view.

ScrollView going behind button in Android

Why is the scrollview going behind the button here? I want the scrollview to stretch in height depending on the device but cant get it to work as it always goes behind the button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/detail_view"
style="#style/DetailView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
style="#style/TextView"
android:id="#+id/textview_message_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
</TextView>
<TextView
style="#style/TextView"
android:id="#+id/textview_message_date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
</TextView>
<ScrollView
android:id="#+id/scrollview_message_text"
android:layout_height="wrap_content"
android:paddingBottom="20dip"
android:layout_width="fill_parent">
<TextView
style="#style/TextView"
android:id="#+id/textview_message_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</ScrollView>
</LinearLayout>
<LinearLayout style="#style/DetailView.Buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
style="#style/Button"
android:layout_marginTop="5dip"
android:id="#+id/button_view_file"
android:text="#string/viewfile"/>
</LinearLayout>
</RelativeLayout>
Here is a working copy of what I think you are looking for
1: Moved the buttons to the top of the relative layout ( added an id )
android:layout_alignParentBottom="true"
<LinearLayout android:id="#+id/buttons"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="5dip"
android:id="#+id/button_view_file"
android:text="Button"/>
</LinearLayout>
2: Add in the layout containing the scroll change the width and height to match parent
but ( CRITICAL ) add android:layout_above="#id/buttons"
<LinearLayout
android:layout_above="#id/buttons"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:gravity="center"
android:orientation="vertical" >
So putting it all together:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/detail_view"
>
<!-- Buttons at the top of layout but aligned to the bottom -->
<LinearLayout android:id="#+id/buttons"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="5dip"
android:id="#+id/button_view_file"
android:text="Button"/>
</LinearLayout>
<!-- Linear layout to fill screen, but assigned to layout above the buttons -->
<LinearLayout
android:layout_above="#id/buttons"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textview_message_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
</TextView>
<TextView
android:id="#+id/textview_message_date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
</TextView>
<ScrollView
android:id="#+id/scrollview_message_text"
android:layout_height="wrap_content"
android:paddingBottom="20dip"
android:layout_width="fill_parent">
<TextView
android:id="#+id/textview_message_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</ScrollView>
</LinearLayout>
</RelativeLayout>
I removed the styles so I could see it in the layout an make sure this worked before posting. Hope this helps.
Relative layout allows you to layer elements on top of each other. So if that is not what you are looking for you need to make use of the toLeft, toRight, above, below directives to nudge the layouts into the correct position.
This happens because you use Relative layout as the root layout. So both layout are placed on the same place but the button layout is declared after the scrollview so it is shown above the scrollview
The opposite would happen if you were defining the button before the scrollview
So you should define it as shown below to achieve what you want.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/detail_view"
style="#style/DetailView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_above="#id/layout_bottom"
android:orientation="vertical" >
<TextView
style="#style/TextView"
android:id="#+id/textview_message_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
</TextView>
<TextView
style="#style/TextView"
android:id="#+id/textview_message_date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
</TextView>
<ScrollView
android:id="#+id/scrollview_message_text"
android:layout_height="wrap_content"
android:paddingBottom="20dip"
android:layout_width="fill_parent">
<TextView
style="#style/TextView"
android:id="#+id/textview_message_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_bottom"
style="#style/DetailView.Buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
style="#style/Button"
android:layout_marginTop="5dip"
android:id="#+id/button_view_file"
android:text="#string/viewfile"/>
</LinearLayout>
</RelativeLayout>
or you can try and use LinearLayout as the root view and set
layout_height = "0dp"
layout_weight = "1"
to the layout containing the scrollview
using both these way will make the button stick to the bottom of the layout and the top layout will get all the remaining height.
Good Luck
Why is the scrollview going behind the button here?
Because it is coming first in your layout, ReletiveLayout and FrameLayout can be used to provide Z-ordering, So every child which comes later in your layout having higher z value so it goes up.Add android:layout_below = "#id/scrollview_message_text" to your last linearlayout or order your views within in mind of this characteristic of reletivelayout.

LinearLayout Buttons not appearing when device orientation changed to Horizontal?

Here is the xml in which ScrollView layout size will vary means it will zoom image on button click but my top headers and footer will always be in same position irrespective of zoom values.......
XML
<?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">
<LinearLayout
android:id="#+id/layout_zoom_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/btn_zoomIn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/zoomin1" />
<ImageView
android:id="#+id/btn_zoomout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/zoomin1" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.example.imagetouchview.TouchImageView
android:id="#+id/imagezoom"
android:layout_width="fill_parent"
android:layout_height="400dp"
android:layout_gravity="center">
</com.example.imagetouchview.TouchImageView>
</ScrollView>
<LinearLayout
android:id="#+id/layout_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/btn_email_fatwa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/zoomin1"
android:layout_weight="1"/>
<ImageView
android:id="#+id/btn_share_fatwa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/zoomin1"
android:layout_weight="1"/>
<ImageView
android:id="#+id/btn_save_fatwa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/zoomin1"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
this layout is fine in vertical orientation while when device orientatio changes to Horizontal the bottom buttons are invisible.I am following Salmans Ayub Answer For Image Zoomin and Out
I think You have design your layout in portrait mode(verticaly). Now either you have to bound it for
portrait mode by adding this line android:screenOrientation="portrait" in your activity manifest,
OR
You have to design it for landscape mode by following this link-
Android: alternate layout xml for landscape mode

Center at the Top

Please have a look at the following code
<ScrollView 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=".DisplayResult" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center"
>
<ImageView
android:id="#+id/zodiac1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/aries"
/>
<TextView
android:id="#+id/orTxt"
android:text="Or"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/zodiac2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/gemini"
/>
</LinearLayout>
</ScrollView>
I want this "LinearLayout" to be centered at the top. Not in the exact center of the device screen. How can I do it? Please help!
EDIT
What I mean is, I want the things inside linear layout to be appeared at the top of the application. They should be centered in that space. If I use RelativeLayout, this is what I do
android:layout_centerHorizontal="true"
android:layout_alignTop="true"
If you want to duplicate RelativeLayout's alignTop, try:
<ScrollView 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=".DisplayResult" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal" >

Categories

Resources