Fix background image on Scrollview Android - android

When I use Scrollview in my codes my background image stretches and scrolls with buttons. I want just buttons scroll, not the background. I have attached a related image that you can figure this out.
Here is the XML file:
<?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 xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/back"
android:orientation="vertical" >
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/app"
android:layout_gravity="center"
android:background="#drawable/bluebutton"
android:layout_marginTop="80dp"
android:layout_marginRight="80dp"
android:layout_marginLeft="80dp"
/>
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/moshiri"
android:background="#drawable/bluebutton"
android:layout_marginTop="8dp"
android:layout_marginRight="80dp"
android:layout_marginLeft="80dp"
/>
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/about"
android:background="#drawable/bluebutton"
android:layout_marginTop="8dp"
android:layout_marginRight="80dp"
android:layout_marginLeft="80dp"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/exit"
android:background="#drawable/bluebutton"
android:layout_marginTop="8dp"
android:layout_marginRight="80dp"
android:layout_marginLeft="80dp"
/>
</LinearLayout>
</ScrollView>

This thing worked fine for me.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/gearImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:clickable="true"
android:src="#drawable/imageName" />
</ScrollView>

Set the background image on the ScrollView and add Padding to the ScrollView or Margins to the Linearlayout.

make 1 Linearlayout at root instead of scrollview and use android:background="#drawable/back" to that layout as
<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="match_parent"
android:background="#drawable/back" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/back"
android:orientation="vertical" >
<ImageButton
android:id="#+id/app"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="80dp"
android:layout_marginRight="80dp"
android:layout_marginTop="80dp"
android:background="#drawable/bluebutton" />
<ImageButton
android:id="#+id/moshiri"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginRight="80dp"
android:layout_marginTop="8dp"
android:background="#drawable/bluebutton" />
<ImageButton
android:id="#+id/about"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginRight="80dp"
android:layout_marginTop="8dp"
android:background="#drawable/bluebutton" />
<ImageButton
android:id="#+id/exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginRight="80dp"
android:layout_marginTop="8dp"
android:background="#drawable/bluebutton" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Here I am assuming that your #drawable/back is your given image background

This worked for me. The image was resized automatically and filled the entire background (Adjusted on width and cropped on height.)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="#drawable/app_back_image" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:isScrollContainer="true">
...
</ScrollView>
</RelativeLayout>

As Raanan said, set the background image on the ScrollView, but to prevent backround from streching on different screen size, you can add gravity to it.
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/back"
android:gravity="top" />

Do this,
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#drawable/back"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/app"
android:layout_gravity="center"
android:background="#drawable/bluebutton"
android:layout_marginTop="80dp"
android:layout_marginRight="80dp"
android:layout_marginLeft="80dp"
/>
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/moshiri"
android:background="#drawable/bluebutton"
android:layout_marginTop="8dp"
android:layout_marginRight="80dp"
android:layout_marginLeft="80dp"
/>
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/about"
android:background="#drawable/bluebutton"
android:layout_marginTop="8dp"
android:layout_marginRight="80dp"
android:layout_marginLeft="80dp"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/exit"
android:background="#drawable/bluebutton"
android:layout_marginTop="8dp"
android:layout_marginRight="80dp"
android:layout_marginLeft="80dp"
/>
</LinearLayout>
</ScrollView>

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".CadetEnrollmentFormActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:src="#drawable/background" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--put your view here -->
</LinearLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>

You can use LinearLayout as a root element of ScrollView.
Then set your background to Linearlayout.
<LinearLayout
.......
android:background="#drawable/background">
<ScrollView
........>
<LinearLayout
.......>
//your code hear
<LinearLayout/>
<ScrollView/>
<LinearLayout/>

Add your manifest to the respective activity
android:windowSoftInputMode="adjustResize"

Related

Imageview not centered in parent - Android

I'm trying to position the blue icon precisely in the center of the card, but for some reason the icon goes up to the top of the card.
Can someone tell me what's wrong?
Thanks,
Here's a screenshot of my problem:
<GridView
android:id="#+id/documents_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:columnWidth="#dimen/document_grid_item_width"
android:gravity="center"
android:horizontalSpacing="0dp"
android:numColumns="auto_fit"
android:stretchMode="spacingWidthUniform"
android:verticalSpacing="48dp" />
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:focusable="true"
android:foreground="?android:selectableItemBackground"
android:background="#drawable/document_grid_item_bg">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/draft_more_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
app:srcCompat="#drawable/ic_more" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:srcCompat="#drawable/draft_icon" />
</RelativeLayout>
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="0.1">
<TextView
android:id="#+id/draft_date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Date" />
</RelativeLayout>
I assume that in gridview item your parent is LinearLayout which can't be seen from your code snippet. If that's the case, in FrameLayout properties set the height to wrap_content
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:focusable="true"
android:foreground="?android:selectableItemBackground"
android:background="#drawable/document_grid_item_bg">
Given code snippet is working fine with LinearLayout as parent.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:focusable="true"
android:background="#color/colorGreen"
android:foreground="?android:selectableItemBackground">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/draft_more_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
app:srcCompat="#drawable/ic_more" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/draft_icon"
android:layout_centerInParent="true" />
</RelativeLayout>
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="0.1">
<TextView
android:id="#+id/draft_date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Date" />
</RelativeLayout>
</LinearLayout>
1. Remove FrameLayout and add its attributes to child RelativeLayout.
2. Use attribute android:src instead of app:srcCompat to set image on ImageView.
Try 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:background="#fff">
<ImageView
android:id="#+id/draft_more_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:src="#drawable/ic_more" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/draft_icon" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="0.1">
<TextView
android:id="#+id/draft_date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="16 May 2017" />
</RelativeLayout>
</LinearLayout>
FYI, If you are using CardView as a container, then just put below LinearLayout inside your CardView.
OUTPUT:

Cannot align Imageview below another Imageview

This is what I am require to do(The menu):
and this is what I have achieved so far:
Please see the horizontal line below an image within the list.I cannot make my screen-shot similar to the requirement.
Code:
popupmenurow.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll_menu_row_cont"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="horizontal" >
<RelativeLayout
android:id="#+id/rl_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imgmenuicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"//this is the image icon
android:layout_margin="10dp"
android:contentDescription="#null" />
<ImageView//this is the horizontal line
android:contentDescription="#null"
android:id="#+id/horizontalline"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_below="#+id/imgmenuicon"
android:layout_alignLeft="#+id/imgmenuicon"
android:layout_alignRight="#+id/imgmenuicon"
android:background="#4d4b56" />
</RelativeLayout>
<ImageView
android:contentDescription="#null"
android:id="#+id/verticalline"
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:background="#4d4b56" />
<TextView
android:id="#+id/tvmenutitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingTop="10dp"
android:text="Hello"
android:textColor="#color/menutextcolor"
android:textSize="16sp" />
</LinearLayout>
and here is the list popup_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical" >
<ListView
android:id="#+id/list_slide"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:choiceMode="singleChoice"
android:divider="#null"
/>
</LinearLayout>
What shall I do to make the horizontal line below the imageview,similar to that of my requirement(The image on the top)?
If I remove
android:layout_alignLeft="#+id/imgmenuicon"
android:layout_alignRight="#+id/imgmenuicon"
then the line is not showing up.Also I understand that the margins occuring to the left and right of the horizontal line is due to android:layout_margin="10dp" within the imageview.But I cannot find a solution.
ANSWER
Thank you all for your precious time.Finally I have solved the problem.The solution of M090009 was close but I couldn't make it.Finally thanks to Vijay for giving me the idea about the background.
What I have done is to cut an image like this:
and set that image as the background of the relative layout within which my menu-icons resides.
Here is the full code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll_menu_row_cont"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="horizontal" >
<RelativeLayout
android:id="#+id/rl_image"
android:background="#drawable/line_box"
android:padding="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imgmenuicon"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#null"
android:layout_centerHorizontal="true"
android:scaleType="centerInside" />
<!-- <View
android:id="#+id/horizontalline"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_alignLeft="#+id/imgmenuicon"
android:layout_alignRight="#+id/imgmenuicon"
android:layout_below="#+id/imgmenuicon"
android:background="#4d4b56"
android:layout_marginTop="5dp"
android:padding="10dp"
android:contentDescription="#null" /> -->
</RelativeLayout>
<ImageView
android:id="#+id/verticalline"
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#4d4b56"
android:contentDescription="#null" />
<TextView
android:id="#+id/tvmenutitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical"
android:paddingLeft="5dp"
android:text="Hello"
android:textColor="#color/menutextcolor"
android:textSize="16sp" />
</LinearLayout>
and here is the output:
Well you can remove the margin on the icon image and set its scaleType to center_corp as follows
<ImageView
android:id="#+id/imgmenuicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"//this is the image icon
android:contentDescription="#null"
android:scaleType="center_corp"/>
If the above solutions not working mean then try this. Because all the solutions are good.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll_menu_row_cont"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:background="#drawable/bordercolor" >
<ImageView
android:id="#+id/imgmenuicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:contentDescription="#null" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.75" >
<TextView
android:id="#+id/tvmenutitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:paddingBottom="10dp"
android:paddingLeft="5dp"
android:paddingTop="10dp"
android:text="Hello"
android:textColor="#android:color/black"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
Change imgmenuicon's attr:
android:layout_margin="10dp"
to
android:padding="10dp"
BTW, the line should use <View ... android:background.../> instead of <ImmageView ... />
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll_menu_row_cont"
android:layout_width="270dp"
android:layout_height="78dp"
android:background="#ffffff"
android:orientation="horizontal" >
<RelativeLayout
android:layout_gravity="center_vertical|left"
android:id="#+id/rl_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imgmenuicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:src="#android:drawable/alert_dark_frame"
android:contentDescription="#null" />
<View
android:contentDescription="#null"
android:id="#+id/horizontalline"
android:layout_width="100dp"
android:layout_height="1dp"
android:layout_below="#id/imgmenuicon"
android:background="#000" />
<View
android:contentDescription="#null"
android:id="#+id/verticalline"
android:layout_width="1dp"
android:layout_toRightOf="#+id/horizontalline"
android:layout_height="fill_parent"
android:background="#4d4b56" />
</RelativeLayout>
<TextView
android:id="#+id/tvmenutitle"
android:layout_gravity="center_vertical|right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Hello"
android:textSize="18sp" />
Try this and let me know!!!:D
Remove the Imageview for that divider and add this:
<View
android:id="#+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/static_account"
android:background="#color/divider"/>

How to cent image buttons vertically on the action bar

I have made a custom theme to display my image buttons on the action bar. I was wondering how I can center these buttons vertically in android.
The code I have written so far.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left|center_vertical"
android:background="#drawable/groups" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center|fill_vertical"
android:background="#drawable/contactlist" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right|center_vertical"
android:background="#drawable/favourites" />
</FrameLayout>
This is what I want
// try this
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#android:color/holo_blue_dark"
android:padding="5dp"
android:layout_weight="1">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/groups" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/white"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#android:color/holo_blue_dark"
android:padding="5dp"
android:layout_weight="1">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/contactlist" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/white"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#android:color/holo_blue_dark"
android:padding="5dp"
android:layout_weight="1">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/favourites" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
Please follow this code.
<?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="match_parent"
android:orientation="horizontal" >
<ImageButton
android:layout_width="0dip"
android:layout_height="50dip"
android:layout_gravity="top|left|center_vertical"
android:layout_weight="1"
android:background="#FE6602" />
<ImageButton
android:layout_width="0dip"
android:layout_height="50dip"
android:layout_gravity="top|center|fill_vertical"
android:layout_weight="1"
android:background="#DBEAF9" />
<ImageButton
android:layout_width="0dip"
android:layout_height="50dip"
android:layout_gravity="top|right|center_vertical"
android:layout_weight="1"
android:background="#FAF2B0" />
</LinearLayout>
Changes:
android:layout_height="50dip" to android:layout_height="wrap_content"
android:background="#FE6602" to android:background="#drawable/contactlist"
I just put simple color and static size or testing purpose work like charm.
You can put the image buttons inside a LinearLayout with vertical orientation, and then set their gravity to android:layout_gravity="center"

Aligning margins correctly in android layout

Given below is the screenshot of my screen which contains a progressbar. As you can see from the screen, the spacing between the left and right of the screens and this progressbar is not equal. It is less towards the right. How can I make this the same as the left with less gap?
Any help is appreciated
Code and screenshot below:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textViewContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/blue"
android:textSize="18sp" />
<TextView
android:id="#+id/textLink"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:textSize="16sp" />
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="10dp"
android:progressDrawable="#drawable/green_progress_color" />
</LinearLayout>
</TableRow>
EDIT
Main Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/bottom_layout_installing"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/total_progress" />
<ProgressBar
android:id="#+id/total_installed_package_installer"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_margin="10dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp" >
<Button
android:id="#+id/buttonAbort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_bg"
android:onClick="onAbortClick"
android:text="#string/abort"
android:textColor="#android:color/white" />
<Button
android:id="#+id/buttonLaunch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/button_bg"
android:text="#string/install"
android:textColor="#android:color/white" />
</LinearLayout>
</LinearLayout>
<ScrollView
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="#id/bottom_layout_installing" >
<TableLayout
android:id="#+id/installingListview"
style="#android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:groupIndicator="#android:color/transparent"
android:listSelector="#android:color/transparent" >
</TableLayout>
</ScrollView>
Looks like your '#drawable/green_progress_color' doesn't stretch. Try with '#android:drawable/progress_horizontal' to check if this is to your layout or your progress drawable.
Don't use a TableRow just on its own like that, remove it and just have the LinearLayout. The TableRow is causing the problem. TableRow must always be nested within a TableLayout(http://developer.android.com/reference/android/widget/TableRow.html)
<?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/textViewContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/blue"
android:textSize="18sp" />
<TextView
android:id="#+id/textLink"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:textSize="16sp" />
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="10dp"
android:progressDrawable="#drawable/green_progress_color" />
</LinearLayout>

Align to the right of the screen with margin Android

I have a Linearlayout within a RelativeLayout that I'm trying to align to the rightmost side of the screen with margin. Example:
How should I modify the LinearLayout's properties to achieve this? thanks
Here is the XML file(the name of the LinearLayout that should be aligned to right is slide_right):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="top"
tools:context=".MainActivity" >
<WebView android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<LinearLayout
android:id="#+id/slide_left"
android:layout_width="400dp"
android:layout_height="550dp"
android:layout_marginLeft="-367dp"
android:layout_marginTop="150dp"
android:background="#drawable/left_slide"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/slide_right"
android:layout_width="400dp"
android:layout_height="550dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="-30dp"
android:orientation="horizontal"
android:background="#drawable/right_slide">
</LinearLayout>
<LinearLayout
android:id="#+id/header_linear_l"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/mapbt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mapbt" />
<ImageButton
android:id="#+id/profilebt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/profilebt" />
<ImageButton
android:id="#+id/settingsbt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/settingsbt" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/optionalbt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/optionbt" />
<ImageButton
android:id="#+id/lvlbt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/levelbt" />
</LinearLayout>
<ProgressBar
android:id="#+id/experiencebar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="#+id/Attack_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/slide_left"
android:layout_marginBottom="129dp"
android:layout_marginLeft="36dp"
android:layout_toRightOf="#+id/slide_left"
android:src="#drawable/ic_launcher_old"
android:visibility="invisible" />
</RelativeLayout>
Change Your Relative layout's Property
from
android:layout_width="wrap_content"
to
android:layout_width="match_parent"
thats it... (definitely I have tested it see below snapshot)
See the following Code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/your_relative_layout_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white" >
<LinearLayout
android:id="#+id/your_linear_layout_id"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="-30dip"
android:background="#e42c2a"
android:orientation="horizontal" >
</LinearLayout>
</RelativeLayout>
Here
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="-30dip"
are of your use.

Categories

Resources