How to adjust graphics to different screens resolution and rotation? - android

I making a checkers game and the code for the xml file is :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/gamebackground" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="260dp"
android:layout_height="260dp"
android:layout_marginBottom="30dp"
android:background="#drawable/board_1_" >
<TableLayout
android:id="#+id/grid"
android:layout_width="221dp"
android:layout_height="213dp"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="16dp"
android:stretchColumns="*" >
</TableLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="#+id/opponent"
android:layout_width="150dp"
android:layout_height="17dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/player"
android:layout_width="150dp"
android:layout_height="17dp"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:gravity="center_vertical|center_horizontal"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="110dp"
android:layout_height="30dp"
android:layout_marginRight="25dp"
android:layout_marginEnd="25dp"
android:layout_marginTop="15dp"
android:gravity="center_vertical|center_horizontal"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="25sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="110dp"
android:layout_height="30dp"
android:layout_marginLeft="25dp"
android:layout_marginStart ="25dp"
android:layout_marginTop="15dp"
android:gravity="center_vertical|center_horizontal"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:gravity="center_horizontal" >
<Button
android:id="#+id/withdraw"
style="?android:attr/buttonStyleSmall"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/mybutton"
android:minHeight="10dp"
android:minWidth="70dp"
android:text="#string/Withdraw"
android:textSize="20sp" />
<Button
android:id="#+id/callfortie"
style="?android:attr/buttonStyleSmall"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginBottom="22dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:background="#drawable/mybutton"
android:minHeight="10dp"
android:minWidth="70dp"
android:text="#string/Callfortie"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
I 'm adding 8 rows each row contains 8 button programmatically and setting these buttons to hold the checkers image ... the problem is I tested this on Nexus one emulator and looked like this
http://i59.tinypic.com/zwb6dj.jpg
but on different resolutions it looks like this
http://i61.tinypic.com/iwucls.jpg
So any help ? :)

It looks like you do not create xml file for multiple screen support.
You should follow multi screen support as per android developer's documents. Please follow below link for more info.
http://developer.android.com/guide/practices/screens_support.html

Related

Android widget not showing up on the emulator screen

I have added some widgets on activity_main.xml, a layout file for main.java in android. When I ran the program on emulator, the last widget is missing in the emulator screen. What will be the reason? How to rectify it?
Here by I am giving below the code for activity_main.xml
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg1"
android:paddingBottom="50dp">
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginTop="0dp"
android:src="#drawable/cmplnlogo"
android:id="#+id/imageViewLogo" />
<EditText
android:layout_marginTop="30dp"
android:layout_width="310dp"
android:layout_height="50dp"
android:layout_marginLeft="30dp"
android:inputType="textEmailAddress"
android:hint="#string/signupUserHint"
android:textSize="15sp"
android:gravity="center"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textColorHint="#FFFFFF"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextEmail" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF00FF"
android:id="#+id/textViewEmailValidator" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:gravity="center"
android:hint="#string/signupPwd"
android:textColorHint="#FFFFFF"
android:inputType="textPassword"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextPwd" />
<EditText
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:gravity="center"
android:hint="#string/signupCfmPwd"
android:textColorHint="#FFFFFF"
android:inputType="textPassword"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextConfirmPwd" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF00FF"
android:id="#+id/textViewPwdValidator" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/signInHint"
android:onClick="GoToLogin"
android:textColor="#FFFFFF"
android:id="#+id/textViewSignin" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/edittextstyle"
android:text="#string/SignUp"
android:onClick="SignUp"
android:textColor="#FFFFFF"
android:id="#+id/buttonSignUp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/service_terms"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textViewServiceTerms" />
</LinearLayout>
</LinearLayout>
I solved the problem mentioned in the above question by adding scrollview widget. I added the scrollview widget in the layout file for which all widgets are not appearing on the emulator. Remember scrollview only suppors only one direct file.
I had many layouts inside the layout file that enclosed different widgets. I enclosed all the layouts with in one layout. And then, enclosed that layout with scrollview. I am giving the snippet.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/scroll">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/username"
android:id="#+id/registerUserName"
android:paddingBottom="10dp"
android:layout_weight="1"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/enterRegisterUserName"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</Scrollview>

Layout weight apparently work well, but not in some real devices

I have searched and tried a lot of solution without success.
I have a full size image in the main screen of my app. So i want to organize this image with 2 buttons on the bottom of the screen.
With this XML everything seems ok but in some devices (HTC One, LG Nexus 4...) the image is not visible . In others devices is all ok and indeed i think the code is pretty good. I know that could be a weight problem but if i use relative layout there is the problem of the overlapping (i don't want use scroll view because the main screen must be all visible immediatly).
What i'm missing?
<?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"
android:background="#drawable/main_gradient">
<ImageView android:id="#+id/imgMainLogo"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:padding="20dp"
android:adjustViewBounds="true"
android:contentDescription="#string/image_description"
android:gravity="center"
android:src="#drawable/logo"/>
<LinearLayout android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:padding="15dp"
android:gravity="bottom">
<Button
android:id="#+id/buttonRegister"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:padding="20dp"
android:text="#string/main_btn_register"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#FFFFFF"
android:background="#drawable/button_background"/>
<Button
android:id="#+id/buttonEnter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:padding="20dp"
android:text="#string/main_btn_enter"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#FFFFFF"
android:background="#drawable/button_background"/>
</LinearLayout>
</LinearLayout>
Checkout the weight related changes that I have made. Let me know if it works.
<?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:background="#drawable/main_gradient"
android:orientation="vertical"
android:weightSum="1" >
<ImageView
android:id="#+id/imgMainLogo"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"
android:adjustViewBounds="true"
android:contentDescription="#string/image_description"
android:gravity="center"
android:padding="20dp"
android:src="#drawable/logo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:gravity="bottom"
android:orientation="horizontal"
android:padding="15dp"
android:weightSum="1" >
<Button
android:id="#+id/buttonRegister"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="0.5"
android:background="#drawable/button_background"
android:padding="20dp"
android:text="#string/main_btn_register"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="#+id/buttonEnter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="0.5"
android:background="#drawable/button_background"
android:padding="20dp"
android:text="#string/main_btn_enter"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:padding="20dp"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:orientation="horizontal"
android:padding="20dp"
android:weightSum="2" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:text="Register"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="Enter"
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>

How to create a login form in Android?

I want to create a login form. But i am new in android so i am not able to do it properly. I have to put the logo of the company on it's header. After that the heading will be Like Login to you are account after that in a box the user name and password. So i am posting my xml please upadte it. Thanks...
This is how i have to create it from this link please check this
http://s23.postimg.org/btie12dvv/Login_Page2.jpg
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#5F04B4"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal" >
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="User Name"
android:textColor="#ffffff"
android:textSize="13dp"
android:textStyle="bold" />
<EditText
android:id="#+id/edtUserName"
android:layout_width="200dp"
android:layout_height="wrap_content" >
</EditText>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Password"
android:textColor="#ffffff"
android:textSize="13dp"
android:textStyle="bold" />
<EditText
android:id="#+id/edtPassword"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:password="true" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<Button
android:id="#+id/btnLogin"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Login" />
</LinearLayout>
</LinearLayout>
For setting company logo in header:
getActionBar().setHomeButtonEnabled(true);
Drawable d=getResources().getDrawable(R.drawable.company_logo.png);
getActionBar().setBackgroundDrawable(d);
For setting title: Login
getActionBar().setTitle("Login");
I hope it will help you.
I created a sample code. You need to replace proper images with sample one.
layout code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imgLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_below="#+id/imgLogo"
android:background="#092EA1"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="Login to Your Account"
android:textColor="#android:color/white"
android:textSize="25sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="260dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="17dp"
android:layout_marginTop="15dp"
android:background="#android:color/darker_gray" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignLeft="#+id/imageView1"
android:layout_alignRight="#+id/imageView1"
android:layout_alignTop="#+id/imageView1"
android:layout_marginLeft="40dp"
android:hint="Usrname" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="260dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView1"
android:layout_marginLeft="17dp"
android:layout_marginTop="15dp"
android:background="#android:color/darker_gray" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView2"
android:layout_alignLeft="#+id/imageView2"
android:layout_alignRight="#+id/imageView2"
android:layout_alignTop="#+id/imageView2"
android:layout_marginLeft="40dp"
android:hint="Password"
android:inputType="textWebPassword" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView2"
android:layout_below="#+id/imageView2"
android:layout_marginTop="26dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView3"
android:layout_alignRight="#+id/imageView2"
android:text="Forget Password?"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
This will look like,
after 1st LinearLayout (root) you can write these lines:
<RelativeLayout
android:id="#+id/headerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top" >
<View
android:id="#+id/headerView"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentTop="true"
android:background="#drawable/Your-header-file-name" />
</RelativeLayout
Alternatively you may use LinearLayout instead of Relative. I used this one because it will not affect your LinearLayout. It's a good practice for beginners to use a weight for LinearLayout like:
<LinearLayout (root)
android:orientation="vertical"
android:weightSum ="2" >
<LineaLayout (child1)
android:layout_weight="1"/>
<LineaLayout (child2)
android:layout_weight="1"/>
</LinearLayout>
this will divide your layouts with weight 1. so you will get half screen for child 1 and remaining half for child 2

Not able to align the button and textView in xml

I have a problem in aligning an button and textView. I already have an textView and button in xml and i want another set of those, just below them.
But i am not able to add it. Please have a look at it.
Here is the xml,
<?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:animateLayoutChanges="true"
android:background="#FFFFFF">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top">
<com.aavishkaar.quikies.widget.TypedfacedTextViewxmlns:your_namespace="http://schemas.android.com/apk/res/com.aavishkaar.quickies"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Click Here"
android:id="#+id/textView"
android:layout_weight="0.6"
android:textSize="24sp"
android:textColor="#android:color/black"
android:gravity="center|left"
android:layout_marginLeft="15dp"
your_namespace:typeface="Roboto-Regular.ttf" />
<Button style="?android:attr/buttonStyleSmall"
android:id="#+id/blue0"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="OFF"
android:layout_weight="0.2"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/switch_bg_holo_light" />
<Button style="?android:attr/buttonStyleSmall"
android:id="#+id/blue1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="ON"
android:layout_weight="0.2"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/switch_thumb_activated_holo_light"/>
</LinearLayout>
</LinearLayout>
Try this code just change orientation in your first linear layout by default linear layout orientation is horizontal
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="#FFFFFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top">
<com.aavishkaar.quikies.widget.TypedfacedTextView
xmlns:your_namespace="http://schemas.android.com/apk/res/com.aavishkaar.quickies"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Click Here"
android:id="#+id/textView"
android:layout_weight="0.6"
android:textSize="24sp"
android:textColor="#android:color/black"
android:gravity="center|left"
android:layout_marginLeft="15dp"
your_namespace:typeface="Roboto-Regular.ttf"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:id="#+id/blue0"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="OFF"
android:layout_weight="0.2"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/switch_bg_holo_light"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:id="#+id/blue1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="ON"
android:layout_weight="0.2"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/switch_thumb_activated_holo_light"
/>
</LinearLayout>
<com.aavishkaar.quikies.widget.TypedfacedTextView
xmlns:your_namespace="http://schemas.android.com/apk/res/com.aavishkaar.quickies"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Click Here"
android:id="#+id/textView"
android:layout_weight="0.6"
android:textSize="24sp"
android:textColor="#android:color/black"
android:gravity="center|left"
android:layout_marginLeft="15dp"
your_namespace:typeface="Roboto-Regular.ttf"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:id="#+id/blue0"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="OFF"
android:layout_weight="0.2"
android:layout_gravity="center_vertical"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/switch_bg_holo_light"
/>
<Button
style="?android:attr/buttonStyleSmall"
android:id="#+id/blue1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="ON"
android:layout_weight="0.2"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/switch_thumb_activated_holo_light"
/>
</LinearLayout>
</LinearLayout>
Add
android:orientation="vertical" in first Linear Layour.
Add
android:orientation="horizontal" in Second Linear Layour.
I hope this will work , if not ignore this answer .
I'm Not very Good at this.

Android: RadioButton within Nested Layout under RadioGroup falls out of Group

I'm trying to get some sensible positioning of my radiobuttons which are part of a RadioGroup. I was having trouble as my RadioGroup was sitting on top of the rest of my layout design, then I use margins to push the buttons around, the problem here is this works on one or two device layouts only. I thought I struck gold when I discovered I could define my RadioGroup then put in a RelativeLayout below which amongst other things contained one of the RadioButtons, then I repeat twice more. this gives me the layout I desire. Problem is, when I run the code, the RadioButtons act link standalone buttons :(
So two questions,
can I link these buttons back to the Group?
Is there a decent way to be able to define the layout of the RadioGroup Radiobuttons independently of the Group.
I am thinking an alternative may be independent RadioButtons and use code to enable/disable them, but that does kind of defeat the usefulness of RadioGroup.
thanks.
Here is my XML layout should you be curious.
<ScrollView android:id="#+id/scrollview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/HDDResultsBox"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:windowSoftInputMode="stateHidden"
>
<RadioGroup android:id="#+id/calcBy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_below="#id/HDDResultsBox"
>
<RelativeLayout android:id="#+id/intervalBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/backgroundbox"
android:layout_margin="5dp"
android:padding="5dp"
>
<TextView android:id="#+id/intervalHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Interval"
android:gravity="left"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_marginLeft="5dp"
/>
<TextView android:id="#+id/intervalHelpText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Interval help text"
android:gravity="left"
android:textColor="#ffffff"
android:textSize="8dp"
android:layout_toRightOf="#id/intervalHeader"
android:layout_marginLeft="10dp"
/>
<LinearLayout android:id="#+id/interval2ndBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/intervalHeader"
android:layout_marginLeft="10dp"
>
<RadioButton android:id="#+id/byInterval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
/>
<EditText android:id="#+id/intervalValue"
android:layout_width="75dp"
android:layout_height="40dp"
android:text="50"
android:textSize="14sp"
android:gravity="center"
android:inputType="number"
android:layout_marginLeft="20dp"
/>
<Spinner android:id="#+id/intervalType"
android:layout_width="match_parent"
android:layout_height="42dp"
android:drawSelectorOnTop="false"
android:layout_marginTop="1dp"
android:layout_marginLeft="10dp"
android:layout_weight="10"
android:layout_marginRight="2dp"
/>
<SeekBar android:id="#+id/intervalSeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="8dp"
android:layout_weight="7"
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout android:id="#+id/recordBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/backgroundbox"
android:layout_margin="5dp"
android:padding="5dp"
>
<TextView android:id="#+id/recordHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Record Duration"
android:gravity="left"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_marginLeft="5dp"
/>
<TextView android:id="#+id/recordHelpText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Record help text"
android:gravity="left"
android:textColor="#ffffff"
android:textSize="8dp"
android:layout_toRightOf="#id/recordHeader"
android:layout_marginLeft="10dp"
/>
<LinearLayout android:id="#+id/record2ndBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/recordHeader"
android:layout_marginLeft="10dp"
>
<RadioButton android:id="#+id/byrecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
/>
<EditText android:id="#+id/recordValue"
android:layout_width="75dp"
android:layout_height="40dp"
android:text="50"
android:textSize="14sp"
android:gravity="center"
android:inputType="number"
android:layout_marginLeft="20dp"
/>
<Spinner android:id="#+id/recordType"
android:layout_width="match_parent"
android:layout_height="42dp"
android:drawSelectorOnTop="false"
android:layout_marginTop="1dp"
android:layout_marginLeft="10dp"
android:layout_weight="10"
android:layout_marginRight="2dp"
/>
<SeekBar android:id="#+id/recordSeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="8dp"
android:layout_weight="7"
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout android:id="#+id/playBackBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/backgroundbox"
android:layout_margin="5dp"
android:padding="5dp"
>
<TextView android:id="#+id/playBackHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Video Length"
android:gravity="left"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_marginLeft="5dp"
/>
<TextView android:id="#+id/playBackHelpText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="playBack help text"
android:gravity="left"
android:textColor="#ffffff"
android:textSize="8dp"
android:layout_toRightOf="#id/playBackHeader"
android:layout_marginLeft="10dp"
/>
<LinearLayout android:id="#+id/playBack2ndBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/playBackHeader"
android:layout_marginLeft="10dp"
>
<RadioButton android:id="#+id/byplayBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
/>
<EditText android:id="#+id/playBackValue"
android:layout_width="75dp"
android:layout_height="40dp"
android:text="50"
android:textSize="14sp"
android:gravity="center"
android:inputType="number"
android:layout_marginLeft="20dp"
/>
<Spinner android:id="#+id/playBackType"
android:layout_width="match_parent"
android:layout_height="42dp"
android:drawSelectorOnTop="false"
android:layout_marginTop="1dp"
android:layout_marginLeft="10dp"
android:layout_weight="10"
android:layout_marginRight="2dp"
/>
<SeekBar android:id="#+id/playBackSeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="8dp"
android:layout_weight="7"
/>
</LinearLayout>
</RelativeLayout>
</RadioGroup>
</RelativeLayout>
</ScrollView>
After looking around for a solution it looks the only way to do this is to use individual radio buttons and then programmically control there on/off states.

Categories

Resources