How to center relative layout with its text and images? - android

I have RelativeLayout which has other elements such as imageview, textview inside it. When i run the app with small screen size (Galaxy S2) it is displayed as image 1. But when it runs on a larger screen (Nexus 7) it is displayed as in image 2. I do not want to enlarge the image for larger screens and i want it to keep certain sizes i set (see .xml). But how i can make it appears at the center on large screens (as in image 3).
Thank you for suggestions.
.xml file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/stainbck"
android:orientation="vertical"
android:padding="25dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Customized Templates"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#eaeaea" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/btn1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:text="1" />
<Button
android:id="#+id/btn2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/btn1"
android:layout_weight="1"
android:text="2" />
<Button
android:id="#+id/btn3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/btn2"
android:layout_weight="1"
android:text="3" />
<Button
android:id="#+id/btn4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="4" />
</LinearLayout>
<LinearLayout
android:id="#+id/relative2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/btn5"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:text="5" />
<Button
android:id="#+id/btn6"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:text="6" />
<Button
android:id="#+id/btn7"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/btn6"
android:layout_weight="1"
android:text="7" />
<Button
android:id="#+id/btn8"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/btn7"
android:layout_weight="1"
android:text="8" />
</LinearLayout>
<RelativeLayout
android:id="#+id/relative"
android:layout_width="265dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:gravity="center"
android:longClickable="true" >
<ImageView
android:id="#+id/blankcard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true" />
<TextView
android:id="#+id/crdCompany"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Company"
android:textColor="#20526d"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="#+id/crdWebsite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="16dp"
android:text="website"
android:textColor="#20526d"
android:textSize="9sp"
android:textStyle="bold" />
<TextView
android:id="#+id/crdAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/crdPhone"
android:layout_alignParentLeft="true"
android:text="address"
android:textColor="#20526d"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="#+id/crdEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/crdWebsite"
android:layout_alignBottom="#+id/crdWebsite"
android:layout_alignParentRight="true"
android:text="email"
android:textColor="#20526d"
android:textSize="9sp"
android:textStyle="bold" />
<TextView
android:id="#+id/crdPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/crdWebsite"
android:layout_alignParentLeft="true"
android:layout_marginBottom="17dp"
android:text="phone"
android:textColor="#20526d"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="#+id/crdName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/crdCompany"
android:text="name"
android:textColor="#20526d"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="#+id/crdTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/crdName"
android:layout_marginTop="12dp"
android:text="title"
android:textColor="#20526d"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="#+id/crdMobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/crdTitle"
android:layout_marginTop="5dp"
android:text="mobile"
android:textColor="#20526d"
android:textSize="13sp"
android:textStyle="bold" />
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="25dp" >
<ImageView
android:id="#+id/crdlogoframe"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#drawable/border"
android:visibility="visible" />
</FrameLayout>
<ImageView
android:id="#+id/crdqrframe"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignTop="#+id/frameLayout1"
android:layout_toRightOf="#+id/frameLayout1"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#drawable/border" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/bottomrltv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dp"
android:gravity="bottom" >
<Button
android:id="#+id/btnsend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/view"
android:layout_weight="1"
android:text="Send" />
<View
android:id="#+id/view"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/btnedit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/btnsend"
android:layout_toRightOf="#+id/view"
android:layout_weight="1"
android:text="Edit" />
</RelativeLayout>
Note: .xml file demonstrates whole interface, not only RelativeLayout.

If i understand you correctly you need to center imageview with id blankcard inside his parent relativelayout? Then you can set android:centerInParent='true'...

Related

Android button text out of border

After looking in google and in the from for set boundaries to fit text in RelativeLayout to the button size.
Android Button layout with big text size didn't help
How to fit text on Button? didn't help
How does setting baselineAligned to false improve performance in LinearLayout? I am on Relative
example from my app:
http://tinypic.com/view.php?pic=2wec9d5&s=8#.VUZns_lVhBc
My xml button:
<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/bg_game"
tools:context=".ClassicMode" >
<Gallery
android:id="#+id/gallery1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:scaleType="fitXY"
android:scaleX="2"
android:scaleY="2" />
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
</LinearLayout>
<TextView
android:id="#+id/numOfGuesses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="23dp"
android:layout_toLeftOf="#+id/linearLayout1"
android:layout_toRightOf="#+id/gallery1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/guesses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/guesses"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="60px" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="23dp"
android:layout_marginTop="18dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="226dp"
android:layout_height="152dp"
android:scaleX="1"
android:scaleY="1"
android:src="#drawable/argentina" />
</LinearLayout>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:background="#android:color/transparent"
android:onClick="check"
android:scaleX="1.5"
android:scaleY="1.5"
android:text="Button"
android:textStyle="bold" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_below="#+id/button1"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:background="#android:color/transparent"
android:onClick="check"
android:scaleX="1.5"
android:scaleY="1.5"
android:text="Button"
android:textStyle="bold" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button3"
android:layout_below="#+id/button3"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:background="#android:color/transparent"
android:onClick="check"
android:scaleX="1.5"
android:scaleY="1.5"
android:text="Button"
android:textStyle="bold" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button2"
android:layout_below="#+id/button2"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:background="#android:color/transparent"
android:onClick="check"
android:scaleX="1.5"
android:scaleY="1.5"
android:text="Button"
android:textStyle="bold" />
<TextView
android:id="#+id/scorenum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/linearLayout1"
android:layout_alignParentLeft="true"
android:textSize="60px" />
<TextView
android:id="#+id/score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/scorenum"
android:layout_alignParentLeft="true"
android:text="#string/score"
android:textSize="60px" />
<Button
android:id="#+id/hint"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/circle"
android:gravity="center_vertical|center_horizontal"
android:text="hint"
android:textColor="#fff" />
</RelativeLayout>
Try setting following properties on your buttons:
android:layout_marginRight="0dp"
android:layout_marginLeft="0dp"
android:singleLine="false" // set this to true if you want your text to be single line
// or to false otherwise
And I suggest removing this line from your buttons:
android:layout_alignLeft="some_button_id"

Android ImageView in Eclipse - Problems with image location

I'm trying to insert some pixel art for my app as an ImageView, but it's very stubborn once I have it in. Specifically, it's centered and pretty much locked into a grid.
I would like to naturally place the sprite where I want to instead of having it snap to a grid. Any suggestions? Here it is:
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/cloud1" />
EDIT: Full XML
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="Enter Two Numbers"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<EditText
android:id="#+id/editOp1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editOp2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal" />
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:gravity="center" >
<ImageButton
android:id="#+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:src="#drawable/sun" />
<Button
android:id="#+id/btnSubtract"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:textStyle="bold" />
<Button
android:id="#+id/btnDivide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:textStyle="bold" />
<Button
android:id="#+id/btnMultiply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*"
android:textStyle="bold" />
<Button
android:id="#+id/clear"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CLR" />
</TableRow>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:gravity="center"
android:text="RESULT"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="0.00"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="#drawable/grass" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/imageView2"
android:src="#drawable/grass" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/imageView3"
android:src="#drawable/grass" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView4"
android:layout_marginLeft="12dp"
android:layout_marginTop="14dp"
android:src="#drawable/cloud2" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="43dp"
android:src="#drawable/cloud1" />
</RelativeLayout>
All you wanted to do is make the xml layout root as RelativeLayout & Go to Design tab, drag to where ever you want it to be.
Hope it helps!

Android : Relativelayout in Framelayout not showing up (Custom Camera Preview Screen)

I need same as I attached image file Its Camera Preview Screen : I want to design two transparent layout over framelayout so it looks like this, but when I run it show only camera screen(Framelayout). It not showing two relative layouts.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:layout_gravity="top"
android:padding="15dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="01"
android:textColor="#color/White" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="5dp"
android:text="Status:"
android:textColor="#color/White" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView1"
android:layout_marginRight="78dp"
android:src="#drawable/heart" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_alignLeft="#+id/imageView3"
android:layout_marginTop="10dp"
android:src="#drawable/view" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView3"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/imageView4"
android:text="125 Likes"
android:textColor="#color/White" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_toRightOf="#+id/textView2"
android:text="STREAMING" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_alignTop="#+id/imageView4"
android:text="24 Viewers"
android:textColor="#color/White" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#77000000"
android:layout_gravity="bottom"
android:padding="10dp" >
<Button
android:id="#+id/button_capture"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/camera_record"
android:textColor="#color/White" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="50dp"
android:src="#drawable/view_video_big" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="50dp"
android:src="#drawable/swipe_camera" />
</RelativeLayout>
</FrameLayout>
Add ids to the two RelativeLlayouts in layout file..
and get the view object by like this
RelativeLayout layout1=(RelativeLayout) findViewById(R.id.topRelativeLayout);
RelativeLayout layout2=(RelativeLayout) findViewById(R.id.bottomRelativeLayout);
and add this line in your onCreate and test once..
layout1.bringToFront();
layout2.bringToFront();
Try this first of all you have to set your background image to FrameLayout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#drawable/ic_launcher"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:padding="15dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="01"
android:textColor="#color/White" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="5dp"
android:text="Status:"
android:textColor="#color/White" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView1"
android:layout_marginRight="78dp"
android:src="#drawable/heart" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_alignLeft="#+id/imageView3"
android:layout_marginTop="10dp"
android:src="#drawable/view" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView3"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/imageView4"
android:text="125 Likes"
android:textColor="#color/White" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_toRightOf="#+id/textView2"
android:text="STREAMING" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_alignTop="#+id/imageView4"
android:text="24 Viewers"
android:textColor="#color/White" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#77000000"
android:layout_gravity="bottom"
android:visibility="visible"
android:padding="10dp" >
<Button
android:id="#+id/button_capture"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/camera_record"
android:textColor="#color/White" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="50dp"
android:src="#drawable/view_video_big" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="50dp"
android:src="#drawable/swipe_camera" />
</RelativeLayout>
</FrameLayout>
or follow this link.

customized list view with text view and button not support for multiple screen?

In my app am using customized listed view with text view and Buttons.The screen size is 4.65" 720p(720X1280 : xhdpi),device take this resolution from layout-large folder.when i run it on device.the list view item and header display not fit to the screen like image shown below,some empty space in the end of row.Its not able to fit to the screen.Can any one know please help me to solve this issue.
Header XML Coding
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/search_lay"
android:layout_marginTop="1dp"
android:background="#e8e8e8" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="32dp"
android:text="Item(s)"
android:textColor="#dd1713"
android:textSize="13sp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="48dp"
android:layout_toRightOf="#+id/textView1"
android:text="Price(Rs.)"
android:textColor="#dd1713"
android:textSize="13sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="18dp"
android:layout_toRightOf="#+id/textView3"
android:text="Qty"
android:textColor="#dd1713"
android:textSize="13sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="28dp"
android:layout_toRightOf="#+id/textView2"
android:text="Total(Rs.)"
android:textColor="#dd1713"
android:textSize="13sp" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="3dp"
android:text="Fav"
android:textColor="#dd1713"
android:textSize="13sp" />
</RelativeLayout>
Customized List-view XML Coding
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#ffffff" >
<TextView
android:id="#+id/orderlist_product_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:visibility="gone" />
<RelativeLayout
android:layout_width="30dp"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/fav_img"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/fav_order_list_btn" />
<Button
android:id="#+id/special_inst_btn"
android:layout_width="25dp"
android:layout_height="18dp"
android:layout_below="#+id/fav_img"
android:layout_centerHorizontal="true"
android:background="#drawable/special_inst_btn_in_orderlist"
android:gravity="center"
android:text="+"
android:textColor="#ffffff"
android:textSize="14sp" />
</RelativeLayout>
<TextView
android:id="#+id/order_list_itemname"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="1dp"
android:text="Item name"
android:textColor="#000000"
android:textSize="12sp"
android:typeface="serif" />
<RelativeLayout
android:layout_width="34dp"
android:layout_height="match_parent"
android:layout_marginLeft="2dp" >
<TextView
android:id="#+id/orderlist_offer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="4dp"
android:gravity="center"
android:textColor="#298616"
android:textSize="10sp" />
<TextView
android:id="#+id/orderlist_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="right"
android:text="200.00"
android:textColor="#000000"
android:textSize="10sp"
android:typeface="serif" />
</RelativeLayout>
<Button
android:id="#+id/orderlist_minus"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginTop="1dp"
android:background="#drawable/sub_button_click" />
<EditText
android:id="#+id/order_list_quantity"
android:layout_width="27dp"
android:layout_height="25dp"
android:layout_marginTop="13dp"
android:background="#drawable/et_bg"
android:ems="10"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:inputType="number"
android:textColor="#000000"
android:textSize="12dp"
android:typeface="serif" >
<requestFocus />
</EditText>
<Button
android:id="#+id/orderlist_plus"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center"
android:layout_marginTop="1dp"
android:background="#drawable/plus_btn_click" />
<TextView
android:id="#+id/orderlist_total"
android:layout_width="43dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginTop="13dp"
android:gravity="right"
android:text="1000.00"
android:textColor="#000000"
android:textSize="11sp"
android:typeface="serif" />
<Button
android:id="#+id/orderlist_delete"
android:layout_width="23dp"
android:layout_height="23dp"
android:layout_gravity="center"
android:layout_marginLeft="3dp"
android:layout_marginTop="1dp"
android:background="#drawable/order_list_delete" />
</LinearLayout>
</RelativeLayout>
i m giving u a demo.this layout will work on all size layout,this will definitely help u #Yugesh.
weight works percentage-wise on all screen.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".30"
android:gravity="center_horizontal" >
<ImageView
android:id="#+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/image1"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".30"
android:text="30%" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".20"
android:text="20%" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".20"
android:text="20%" />
</LinearLayout>
</RelativeLayout>
further more,if there is any query,then please ask...

margin of text doesn't display corectly on different screens

When I work on one android device and set the marginLeft of a text it looks good.
Then I connect another device and the margin is screwed up....
How can I make sure text (and also sizes of buttons) are displayed correctly on ALL android devices.
BTW yeah I'm allready using 'dp'
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/speler_image"
android:layout_width="fill_parent"
android:layout_height="159dp"
android:layout_marginTop="0dp" />
<ImageView
android:id="#+id/speler_infoblock"
android:src="#drawable/playerinfoblock"
android:layout_width="fill_parent"
android:layout_height="107dp"
android:scaleType="fitXY"
android:layout_marginTop="159dp" />
<TextView
android:text="Positie:"
android:textSize="17dp"
android:textColor="#0096d6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"
android:layout_marginLeft="15dp" />
<TextView
android:id="#+id/spelerPositie"
android:text="0"
android:textSize="32dp"
android:textColor="#01428b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="210dp"
android:layout_alignParentRight="true"
android:paddingRight="330dp" />
<TextView
android:text="Score:"
android:textSize="16dp"
android:textColor="#0096d6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"
android:layout_marginLeft="100dp" />
<TextView
android:id="#+id/spelerScore"
android:text="0"
android:textSize="16dp"
android:textColor="#01428b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"
android:layout_alignParentRight="true"
android:paddingRight="160dp" />
<TextView
android:text="Dagscore:"
android:textSize="16dp"
android:textColor="#0096d6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="230dp"
android:layout_marginLeft="100dp" />
<TextView
android:id="#+id/spelerDagscore"
android:text="0"
android:textSize="16dp"
android:textColor="#01428b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="230dp"
android:layout_alignParentRight="true"
android:paddingRight="160dp" />
<TextView
android:text="Hole:"
android:textSize="16dp"
android:textColor="#0096d6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"
android:layout_marginLeft="280dp" />
<ImageView
android:src="#drawable/holeround"
android:layout_width="45dp"
android:layout_height="44dp"
android:layout_marginTop="170dp"
android:layout_alignParentRight="true"
android:paddingRight="7dp" />
<TextView
android:id="#+id/spelerHole"
android:text="0"
android:textSize="24dp"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="175dp"
android:layout_alignParentRight="true"
android:paddingRight="14dp" />
<ImageView
android:id="#+id/plaatsReactie"
android:src="#drawable/plaats_reactie"
android:layout_width="149dp"
android:layout_height="42dp"
android:scaleType="fitXY"
android:layout_marginTop="224dp"
android:layout_alignParentRight="true" />
<TextView
android:text="Plaats reactie"
android:textSize="15dp"
android:textColor="#0096d6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="233dp"
android:layout_marginLeft="306dp" />
<LinearLayout
android:background="#034489"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="266dp" />
<ImageView
android:id="#+id/clickBiografie"
android:layout_width="100dp"
android:layout_height="47dp"
android:scaleType="fitXY"
android:layout_marginTop="266dp"
android:layout_marginLeft="0dp" />
<TextView
android:text="Biografie"
android:textSize="17dp"
android:textColor="#FFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="278dp"
android:layout_marginLeft="14dp" />
<ImageView
android:id="#+id/clickScore"
android:layout_width="100dp"
android:layout_height="47dp"
android:scaleType="fitXY"
android:layout_marginTop="266dp"
android:layout_marginLeft="100dp" />
<TextView
android:text="Score"
android:textSize="17dp"
android:textColor="#FFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="278dp"
android:layout_marginLeft="127dp" />
<ImageView
android:id="#+id/clickReacties"
android:layout_width="100dp"
android:layout_height="47dp"
android:scaleType="fitXY"
android:layout_marginTop="266dp"
android:layout_marginLeft="200dp" />
<TextView
android:text="Reacties"
android:textSize="17dp"
android:textColor="#FFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="278dp"
android:layout_marginLeft="220dp" />
<ImageView
android:id="#+id/clickTwitter"
android:layout_width="100dp"
android:layout_height="47dp"
android:scaleType="fitXY"
android:layout_marginTop="266dp"
android:layout_marginLeft="300dp" />
<TextView
android:text="Twitter"
android:textSize="17dp"
android:textColor="#FFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="278dp"
android:layout_marginLeft="324dp" />
<RelativeLayout
android:id="#+id/biografieLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="313dp">
<ImageView
android:src="#drawable/hole_infoline"
android:layout_width="375dp"
android:layout_height="5dp"
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp" />
<TextView
android:text="Country"
android:textSize="16dp"
android:textColor="#0096d6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="25dp" />
<TextView
android:id="#+id/countryText"
android:textSize="16dp"
android:textColor="#FFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="160dp" />
<ImageView
android:src="#drawable/hole_infoline"
android:layout_width="375dp"
android:layout_height="5dp"
android:layout_marginTop="80dp"
android:layout_marginLeft="20dp" />
<TextView
android:text="Date of Birth"
android:textSize="16dp"
android:textColor="#0096d6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_marginLeft="25dp" />
<TextView
android:id="#+id/dobText"
android:textSize="16dp"
android:textColor="#FFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_marginLeft="160dp" />
<ImageView
android:src="#drawable/hole_infoline"
android:layout_width="375dp"
android:layout_height="5dp"
android:layout_marginTop="120dp"
android:layout_marginLeft="20dp" />
<TextView
android:text="Height / Weight"
android:textSize="16dp"
android:textColor="#0096d6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:layout_marginLeft="25dp" />
<TextView
android:id="#+id/heightweightText"
android:textSize="16dp"
android:textColor="#FFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:layout_marginLeft="160dp" />
<ImageView
android:src="#drawable/hole_infoline"
android:layout_width="375dp"
android:layout_height="5dp"
android:layout_marginTop="160dp"
android:layout_marginLeft="20dp" />
<TextView
android:text="Turned Pro"
android:textSize="16dp"
android:textColor="#0096d6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="130dp"
android:layout_marginLeft="25dp" />
<TextView
android:id="#+id/turnedProText"
android:textSize="16dp"
android:textColor="#FFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="130dp"
android:layout_marginLeft="160dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/scoreLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="313dp">
</RelativeLayout>
<RelativeLayout
android:id="#+id/reactiesLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="313dp">
</RelativeLayout>
<ScrollView
android:id="#+id/twitterLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="313dp">
</ScrollView>
</RelativeLayout>
You can only be sure it displayed properly by testing. You can do some pre testing through eclipse. If you open the xml in eclipse you can click on "graphical layout" and then you can change the phone (screen size) you get a preview on.
If you want your layout to take % of the screen use linearlayout as parent and use weights for defining the percentage the views should take of the screen.
You say you have problems with your margins, this makes no sense as the margins will be what you define them to. So I assume your saying your can't get everything to align properly how you want it too... If that is the case you should use some kind of anchor point and then define the other layouts accordingly. You could for example create a container view (linear/relative etc.) inside your parent view and have that container centered.

Categories

Resources