Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: imageView padding

I'm trying to add a picture via imageView. But I want to full fill my view with the image and also the imageView should fill the width of the screen. the image should begin and end at the screen edge's.

I used every xml attributes but no luck. This is the closest code to what I want.

<RelativeLayout 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/bck3"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<Button
    android:id="@+id/buttonStore"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_alignBottom="@+id/imageView1"
    android:layout_alignParentRight="true"
    android:layout_marginRight="10dp"
    android:background="@drawable/store" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="100dp"
    android:layout_height="40dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/logo" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="fill_parent"
    android:layout_height="125dp"
    android:layout_marginTop="57dp"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    android:src="@drawable/ronaldo" />

Screenshot

It should be this What it should look like

like image 747
Arda Oğul Üçpınar Avatar asked Aug 22 '13 14:08

Arda Oğul Üçpınar


People also ask

What does android padding do?

The padding is expressed in pixels for the left, top, right and bottom parts of the view. Padding can be used to offset the content of the view by a specific number of pixels. For instance, a left padding of 2 will push the view's content by 2 pixels to the right of the left edge.

What is padding and margin in android?

Note that padding goes completely around the content: there is padding on the top, bottom, right and left sides (which can be independent). Margins are the spaces outside the border, between the border and the other elements next to this view. In the image, the margin is the grey area outside the entire object.

What is padding android studio?

Padding in Android is used to add a blank space between a view and its contents. Margins, on the other hand, are used to add a space between two different views.

What is layout_ margin in android?

Margin specifies an extra space outside that View on which we applied Margin. In simple words, Margin means to push outside. Diagrammatically, the margin is shown below: Syntax: android:layout_margin=”size in dp”


2 Answers

try removing the following code from relative layout properties:

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
like image 186
Chintan Soni Avatar answered Oct 21 '22 08:10

Chintan Soni


android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"

Remove the padding on the parent layout, your imageview will then fill the entire width

like image 38
M.Bennett Avatar answered Oct 21 '22 08:10

M.Bennett