Hello, i'm new to the android(also java) so i try to create some easy app. This app will have one base layout from xml and the dynamic layout which will be create from code and will be insert into that base layout. But when i use the findViewbyId it won't work, it return as null.
After that i try to insert "setContentView" before trying findViewbyId and also clean project... and it still got NULL ..
Here are my code..
package com.app.something;
import android.os.Build;
import android.os.Bundle;
import android.annotation.TargetApi;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.GridLayout;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
LinearLayout lLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_main);
GridLayout grid = new GridLayout(this);
grid.setColumnCount(5);
for (int i = 0;i<20;i++){
ImageButton ib = new ImageButton(this);
ib.setImageResource(R.drawable.ic_launcher);
ib.setId(i+1);
final int index = i;
ib.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.i("TAG","The index is" + index);
}
});
grid.addView(ib);
}
lLayout = (LinearLayout)findViewById(R.layout.activity_main);
if(lLayout == null)Log.i("TAG", "It said, NULLL");
else {
lLayout.addView(grid);
setContentView(lLayout);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
and this is the base layout activity_main (blank)
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#ffffff00"
tools:context=".MainActivity" >
</RelativeLayout>
Firt you are trying to cast a RelativeLayout to a LinearLayout. Second you missed the id attribute for your LinearLayout
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#ffffff00"
android:id="#+id/myId"
tools:context=".MainActivity" >
</LinearLayout>
after fix that you can retrieve your layout this way:
lLayout = (LinearLayout)findViewById(R.id.myId);
change
lLayout = (LinearLayout)findViewById(R.layout.activity_main);
to
RelativeLayout lLayout = (RelativeLayout)findViewById(R.id.activity_main);
because activity_main layout conatin RelativeLayout layout as root View instead of LinearLayout and you also need to define android:id for RelativeLayout layout.
or you can do it as using LayoutInflater :
View lLayout = getLayoutInflater().inflate(R.layout.activity_main);
if(lLayout == null)
Log.i("TAG", "It said, NULLL");
else {
lLayout.addView(grid);
setContentView(lLayout);
}
lLayout = (LinearLayout)findViewById(R.layout.activity_main);
1.you have to pass ID for that view, add android:id attribute to relative layout.
2.you dont have any linear layout in your code
3.you have a relative layout cast this to RelativeLayout
you can not use
lLayout = (LinearLayout)findViewById(R.layout.activity_main);
as per the method name it finds the view By id of the view, not the resource id like you are using. you can access a view by an id that is set by using
android:id="#+id/someid"
then from code
lLayout = (LinearLayout)findViewById(R.id.someid);
findViewById searches in your layout, so e.g.:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#ffffff00"
tools:context=".MainActivity" >
</RelativeLayout>
The you can use it:
(RelativeLayout) findViewById(R.id.layout_main);
Related
Pretty new to android development, I need to know how I can change the size of my ListView in my fragment pragmatically to cover the entire screen? match_parent, fill_parent didn't work.
I have hard coded values of 500dp
Here is my fragment
<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"
tools:context=".MainActivity">
<ListView
android:id="#android:id/list"
android:layout_width="500dp"
android:layout_height="500dp"
android:divider="#null"
android:dividerHeight="0dp"
android:layout_marginTop="0dp">
</ListView>
</RelativeLayout>
and here is JAVA my fragment code:
import android.app.ListFragment;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import java.util.List;
public class MyFragment extends ListFragment {
List<data> flowers = new datadata().getdatas();
public MyFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dataArrayAdapter adapter = new dataArrayAdapter(getActivity(),
R.layout.data_listitem,
flowers);
setListAdapter(adapter);
}
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.my_fragment, container, false);
return rootView;
}
}
here is my main Activity class
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/myContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarStyle="insideOverlay"
android:scrollbars="none"
android:fadeScrollbars="true"
android:fitsSystemWindows="true"
android:layout_gravity="top"
>
</ScrollView >
and this is my main activity java code:
package mshirvan.example.com.netplex;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.Intent;
import android.media.Image;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import android.view.View.OnClickListener;
import data.row1;
public class MainActivity extends Activity {
public static float screenx = 0;
public static float screeny = 0;
public static int screenpixelx = 0;
public static int screenpixely = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ScreenUtility utility = new ScreenUtility(this);
screenx = utility.getWidth();
screeny = utility.getHeight();
screenpixelx = utility.getPixelWidth();
screenpixely = utility.getPixelHeight();
MyFragment frag = new MyFragment();
getFragmentManager().beginTransaction()
.add(R.id.myContainer, frag)
.commit();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
ScreenUtility utility = new ScreenUtility(this);
String output = "Width: " + utility.getWidth() + ", " +
"Height: " + utility.getHeight();
return true;
}
return super.onOptionsItemSelected(item);
}
}
Add the following to your fragment RelativeLayout. This should be as follows:
android:layout_width="match_parent"
android:layout_height="500dp"
For example the map layout fragment should be as follows :
<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="500dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
>
<com.google.android.gms.maps.MapView
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
Then add this fragment layout in the main layout.
put these in your listview too:
android:layout_width="match_parent"
android:layout_height="match_parent"
or you can change the layoutparameters to match_parent in yout fragment
that contains the listview.
you have to set the fragment container height to match parent not ListView. in your case ,ListView will fill it's parent height. ListView's parent is RelativeLayout and the RelativeLayout height is matchParent that means , RelativeLayout will also fill it's container and it's container is your fragment place holder that defined in your activity's layout file. you have to set that container's height to matchParent.
I think the problem is that you are trying to add fragment to ScrollView. use FrameLayout with android:layout_height=match_parent for fragment's container and if you have to add multiple fragments, then define multiple FrameLayouts in your activity's layout or add them dynamically.
I'm trying to use Android Annotations and dynamically add layout components when my createNewRow button is clicked. The app runs and displays the default rows defined in activity_main.xml and, after clicking createNewButton I see children attached to my dynamicTable in the debugger but the new children are not displayed. Here is my main activity XML:
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/inflateLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="net.richardriley.inflate.app.MainActivity">
<Button
android:id="#+id/createNewRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/newRowButton"/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/dynamicTable">
<TableRow>
<TextView
android:text="#string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
</LinearLayout>
So simply a linear layout with a button and then a table container. Clicking createNewRow should add a new InflatedRow. Here is the XML for the row I want to dynamically add:
inflatedrow.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView
android:id="#+id/inflatedRowTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/inflatedRowLabel"/>
<Button
android:id="#+id/inflatedRowButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/defaultNewRowText"
/>
</merge>
Using AA my subclass for a tableRow is
InflatedRow.java
package net.richardriley.inflate.app;
import android.content.Context;
import android.widget.Button;
import android.widget.TableRow;
import android.widget.TextView;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;
/**
* inflate : Created by rgr on 20/03/14.
*/
#EViewGroup(R.layout.inflatedrow)
public class InflatedRow extends TableRow {
#ViewById
Button inflatedRowButton;
#ViewById
TextView inflatedRowTextView;
public InflatedRow(Context context) {
super(context);
}
}
and finally my main activity java itself:
MainActivity.java
package net.richardriley.inflate.app;
import android.support.v7.app.ActionBarActivity;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import org.androidannotations.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static ch.qos.logback.classic.android.BasicLogcatConfigurator.configureDefaultContext;
#OptionsMenu(R.menu.main)
#EActivity(R.layout.activity_main)
public class MainActivity extends ActionBarActivity {
static {
configureDefaultContext();
log = LoggerFactory.getLogger(MainActivity.class);
}
#ViewById
LinearLayout inflateLayout;
#ViewById
TableLayout dynamicTable;
public MainActivity() {
}
protected static Logger log;
#Click
void createNewRow() {
log.info("clicked");
InflatedRow_ inflatedRow=new InflatedRow_(this);
dynamicTable.addView(inflatedRow,0);
/*LayoutInflater layoutInflater= (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.inflatedrow,null);
dynamicTable.addView(view);*/
}
#OptionsItem
void openSettingsSelected(){
log.info("Hello");
}
}
In createNewRow if I use the inflater service directly it works.
What am I missing?
many thanks.
Don't use the annotated class when you're inflating the view and make sure you're calling the build method that inflates it.
#Click
void createNewRow() {
log.info("clicked");
InflatedRow inflatedRow = new InflatedRow_.build(this);
dynamicTable.addView(inflatedRow,0);
}
instead of 'View inflatedRow= new InflatedRow_(this);' I use 'View inflatedRow=InflatedRow_.build(this);'. This is documented for custom controls and I needed to do it for a merged control group too. So mea culpa to a degree!
#Click
void createNewRow() {
log.info("clicked");
InflatedRow_ inflatedRow=InflatedRow_.build(this);
dynamicTable.addView(inflatedRow,0);
}
Alternatively (and no idea if this would continue to be supported:
#Click
void createNewRow() {
log.info("clicked");
/*View inflatedRow = InflatedRow_.build(this);*/
InflatedRow_ inflatedRow = new InflatedRow_(this);
inflatedRow.onFinishInflate();
dynamicTable.addView(inflatedRow, 0);
}
I have an image within a relative layout and a linear layout below the image. This image is transparent so it looks like nothing is there.
My code adds 3 text views to the linear layout.
I have it so that when I move my finger on the screen it enlarges height of the image, thus giving the impression that the linear layout has moved down the screen.
I want to get it so that when the screen is being touched, so even if the finder is still, the image gets bigger, making it look like the image is moving down the screen. When the finger is removed the image stops enlarging.
I've been trying to create a thread to run onTouchEvent for about 2 weeks now, but my code just seems to crash the app.
Could someone amend my code / add this functionality so I can see where I'm going wrong. I'm hoping I'm just not putting the thread in the correct location or i'm not stopping the thread correctly which is causing it to crash.
My Layout
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
android:id="#+id/LinearLayout"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/Spacer"
android:layout_width="100dp"
android:layout_height="100dp"
android:contentDescription="Spacer"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:id="#+id/Letters"
android:orientation="horizontal"
android:layout_below="#id/Spacer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
</LinearLayout>
</RelativeLayout>
My Activity
package com.example.zz;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
protected int splashTime = 3000;
TextView tv1;
ImageView spacer;
String[] name = {"Hello","Rich","You","Hero"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] letters = {"A","B","C"};
String letter = "";
String nextLetters = "";
for( int i = 0; i < letters.length; i++)
{
letter = letters[i];
nextLetters = nextLetters + letter;
// Create a textView in code
LayoutParams paramsExample = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,1);
View linearLayout = findViewById(R.id.Letters);
TextView tv1 = new TextView(this);
tv1.setText(letter);
tv1.setLayoutParams(paramsExample);
tv1.setGravity(Gravity.CENTER);
((LinearLayout) linearLayout).addView(tv1);
}
}
#Override
public boolean onTouchEvent(MotionEvent e) {
switch (e.getAction()) {
case MotionEvent.ACTION_MOVE:
spacer = (ImageView) findViewById(R.id.Spacer);
RelativeLayout.LayoutParams head_params = (RelativeLayout.LayoutParams)spacer.getLayoutParams();
head_params.height = 400;
spacer.setLayoutParams(head_params);
}
return true;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
I am just using the launch icon as the image.
Any help would easy my hair loss, thanks in advance.
You can set up a boolean that is false. If ACTION_MOVE is called you set it true and when ACTION_UP is called you set it false again.
Then you call run every x milliseconds by using the handler
implement runnable and assign the handler
private Handler handler = new Handler();
In on create:
handler.postDelayed(this,TIME);
Then call run:
#Override
public void run(){
if (yourboolean == true){
spacer = (ImageView) findViewById(R.id.Spacer);
RelativeLayout.LayoutParams head_params = (RelativeLayout.LayoutParams)spacer.getLayoutParams();
head_params.height += 100;
spacer.setLayoutParams(head_params);
}
handler.postDelayed(this,TIME);
}
I would like to have a ScrollView with a LinearLayout containing two views. The first view should occupy the full screen, with the second view initially off the screen (but it can be scrolled to). Is this achievable?
use this 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"
android:fillViewport="true"
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" >
<LinearLayout
android:id="#+id/linlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/f1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#468432" >
</FrameLayout>
<FrameLayout
android:id="#+id/f2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ff8222" >
</FrameLayout>
</LinearLayout>
</ScrollView>
and your activity gose like following
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.LinearLayout.LayoutParams;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
public class MainActivity extends Activity {
LinearLayout layout ;
FrameLayout f1,f2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layout = (LinearLayout)findViewById(R.id.linlayout);
f1=(FrameLayout) findViewById(R.id.f1);
f2=(FrameLayout) findViewById(R.id.f2);
ViewTreeObserver vto = layout.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
int width = layout.getMeasuredWidth();
int height = layout.getMeasuredHeight();
f1.setLayoutParams(new LayoutParams(width, height));
f2.setLayoutParams(new LayoutParams(width, height));
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
You don't need a ScrollView, a ViewPager is more suited to your needs. Also, since you want it to be vertical, you should check this out: Directional ViewPager
I had the hardest time once trying to achieve this in the iphone, maybe the ideas will help you. What I had was a background view with a notebook style set of lines, and a view on top of that with text, and of course they had to scroll together. I added both to the ScrollView and just intercepted the "scrollViewDidScroll" for view1 and did a view2.contentOffset=view2.contentOffset so that they stayed 'glued'. i just started on Android so I wouldn't know how to exactly achieve this there, but I think the principle wouldn't be much different. Hope this helps :)
Within my layout xml file I would like the 'android:src=""' to pull a random image from a 'bg' folder within drawable.
I know this can be done pragmatically but I'd like to keep it within the layout files.
Is there any way to create an array of everything in the bg folder and pull from it from within the layout xml?
short answer is no, but I can provide source code to help do it programmatically
EDIT: You need to place all the images you want to use in your drawables folder, then in bg.xml put the ones that you want to appear in the button, see the example below, goodluck!
MainActivity.java
package com.example.stackoverflow17462606;
import java.util.Random;
import android.os.Bundle;
import android.app.Activity;
import android.content.res.TypedArray;
import android.view.Menu;
import android.widget.ImageView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageResource(getRandomImage());
}
private int getRandomImage() {
TypedArray imgs = getResources().obtainTypedArray(R.array.random_imgs);
// or set you ImageView's resource to the id
int id = imgs.getResourceId(new Random().nextInt(imgs.length()), -1); //-1 is default if nothing is found (we don't care)
imgs.recycle();
return id;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
bg.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="random_imgs">
<item>#drawable/ic_launcher</item>
<item>#drawable/ic_settings</item>
<!-- ... -->
</string-array>
</resources>
activity_main.xml
<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: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" >
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>
</RelativeLayout>