I have been working on my first app in Android and have study various beginners books on the subject. At the moment the first app is purely for my use to make sure that I understand the language before I step into the realms of uploading to the market. However it may get uploaded if I am to get it to work correctly :) .
My current issue that I have is that my landscape main.xml behaves differently when run through the emulator to when I run it on my phone (samsung Galaxy S2). Now I know that the screen on my phone is larger that the emulator but I would have thought that the settings in my main.xml would stop the edittext from stretching too much.
Here is my main.xml attempt 1 from my layout-land folder and it is my Player2_name edit text object that stretches :
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/ android"
android:orientation="vertical" <----- tried this with
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#006400"
>
<EditText android:id="@+id/Player1_name"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:text="Player 1" />
<EditText android:id="@+id/Player2_name"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_height="wrap_content"
android:layout_width="200dp" android:text="Player 2"
/> <RadioButton
android:id="@+id/Players1_turn"
android:layout_below="@+id/Player1_name"
android:layout_width="150dp"
android:layout_height="35dp"
android:text="turn?"
android:textSize="15px"
/> <RadioButton
android:id="@+id/Players2_turn"
android:layout_below="@+id/Player2_name"
android:layout_toRightOf="@开发者_开发知识库+id/Players1_turn"
android:layout_alignLeft="@+id/Player2_name"
android:layout_alignTop="@+id/Players1_turn"
android:layout_width="150dp"
android:layout_height="35dp"
android:text="turn?"
android:textSize="15px"
/>
<TextView
android:id="@+id/Player1_score"
android:layout_below="@+id/Players1_turn"
android:layout_alignLeft="@+id/Player1_score"
android:text="Score :"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> <TextView
android:id="@+id/Player2_score"
android:layout_below="@+id/Players2_turn"
android:layout_alignLeft="@+id/Players2_turn"
android:layout_alignTop="@+id/Player1_score"
android:text="Score :"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> <ImageButton
android:background="@drawable/red_ball" android:id="@+id/redball"
android:layout_width="65dp" android:layout_height="65dp"
android:layout_below="@+id/Player1_score"
/>
<ImageButton android:background="@drawable/black_ball"
android:id="@+id/blackball" android:layout_width="65dp"
android:layout_height="65dp" android:layout_toRightOf="@+id/redball"
android:layout_alignTop="@+id/redball"
/>
<ImageButton android:background="@drawable/green_ball"
android:id="@+id/greenball" android:layout_width="65dp"
android:layout_height="65dp"
android:layout_toRightOf="@+id/blackball"
android:layout_alignTop="@+id/blackball" />
<ImageButton android:background="@drawable/cue_ball"
android:id="@+id/cueball" android:layout_width="65dp"
android:layout_height="65dp"
android:layout_toRightOf="@+id/greenball"
android:layout_alignTop="@+id/greenball" /> <ImageButton
android:background="@drawable/blue_ball" android:id="@+id/blueball"
android:layout_width="65dp" android:layout_height="65dp"
android:layout_below="@+id/redball"
android:layout_alignLeft="@+id/redball" /> <ImageButton
android:background="@drawable/pink_ball" android:id="@+id/pinkball"
android:layout_width="65dp" android:layout_height="65dp"
android:layout_toRightOf="@+id/blueball"
android:layout_alignTop="@+id/blueball" /> <ImageButton
android:background="@drawable/yellow_ball"
android:id="@+id/yellowball" android:layout_width="65dp"
android:layout_height="65dp" android:layout_toRightOf="@+id/pinkball"
android:layout_alignTop="@+id/pinkball" /> <ImageButton
android:background="@drawable/brown_ball" android:id="@+id/brownball"
android:layout_width="65dp" android:layout_height="65dp"
android:layout_toRightOf="@+id/yellowball"
android:layout_alignTop="@+id/yellowball" /> <CheckBox
android:id="@+id/Foul"
android:layout_below="@+id/blueball"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Foul" /> <CheckBox
android:id="@+id/Sound_on_off"
android:layout_toRightOf="@+id/Foul"
android:layout_width="fill_parent"
android:layout_alignTop="@+id/Foul"
android:layout_height="50dp"
android:text="Sound Effect" />
</RelativeLayout>
Here is my main.xml attempt 2 from my layout-land folder and it is my Player2_name edit text object that stretches :
<?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"
android:background="#006400"
>
<EditText
android:id="@+id/Player1_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:text="Player 1"
/>
<EditText
android:id="@+id/Player2_name"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Player 2"
/>
<RadioButton
android:id="@+id/Players1_turn"
android:layout_below="@+id/Player1_name"
android:layout_width="150dp"
android:layout_height="35dp"
android:text="turn?"
android:textSize="15px"
/> <RadioButton
android:id="@+id/Players2_turn"
android:layout_below="@+id/Player2_name"
android:layout_toRightOf="@+id/Players1_turn"
android:layout_alignLeft="@+id/Player2_name"
android:layout_alignTop="@+id/Players1_turn"
android:layout_width="150dp"
android:layout_height="35dp"
android:text="turn?"
android:textSize="15px"
/>
<TextView
android:id="@+id/Player1_score"
android:layout_below="@+id/Players1_turn"
android:layout_alignLeft="@+id/Player1_score"
android:text="Score :"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> <TextView
android:id="@+id/Player2_score"
android:layout_below="@+id/Players2_turn"
android:layout_alignLeft="@+id/Players2_turn"
android:layout_alignTop="@+id/Player1_score"
android:text="Score :"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> <ImageButton
android:background="@drawable/red_ball" android:id="@+id/redball"
android:layout_width="65dp" android:layout_height="65dp"
android:layout_below="@+id/Player1_score" />
<ImageButton android:background="@drawable/black_ball"
android:id="@+id/blackball" android:layout_width="65dp"
android:layout_height="65dp" android:layout_toRightOf="@+id/redball"
android:layout_alignTop="@+id/redball" />
<ImageButton android:background="@drawable/green_ball"
android:id="@+id/greenball" android:layout_width="65dp"
android:layout_height="65dp"
android:layout_toRightOf="@+id/blackball"
android:layout_alignTop="@+id/blackball" />
<ImageButton android:background="@drawable/cue_ball"
android:id="@+id/cueball" android:layout_width="65dp"
android:layout_height="65dp"
android:layout_toRightOf="@+id/greenball"
android:layout_alignTop="@+id/greenball" /> <ImageButton
android:background="@drawable/blue_ball" android:id="@+id/blueball"
android:layout_width="65dp" android:layout_height="65dp"
android:layout_below="@+id/redball"
android:layout_alignLeft="@+id/redball" /> <ImageButton
android:background="@drawable/pink_ball" android:id="@+id/pinkball"
android:layout_width="65dp" android:layout_height="65dp"
android:layout_toRightOf="@+id/blueball"
android:layout_alignTop="@+id/blueball" /> <ImageButton
android:background="@drawable/yellow_ball"
android:id="@+id/yellowball" android:layout_width="65dp"
android:layout_height="65dp"
android:layout_toRightOf="@+id/pinkball"
android:layout_alignTop="@+id/pinkball" /> <ImageButton
android:background="@drawable/brown_ball"
android:id="@+id/brownball" android:layout_width="65dp"
android:layout_height="65dp"
android:layout_toRightOf="@+id/yellowball"
android:layout_alignTop="@+id/yellowball" /> <CheckBox
android:id="@+id/Foul"
android:layout_below="@+id/blueball"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Foul" /> <CheckBox
android:id="@+id/Sound_on_off"
android:layout_toRightOf="@+id/Foul"
android:layout_width="fill_parent"
android:layout_alignTop="@+id/Foul"
android:layout_height="50dp"
android:text="Sound Effect" />
</RelativeLayout>
As I thought in my previous comment - it is to do with my misunderstanding of how the orientation is handled . I have got this resolved now so I will mark this as solved
精彩评论