Android 1.5 SDK +相对布局EditText 在横向视图中拉伸
我一直在开发我的第一个 Android 应用程序并进行了研究 有关该主题的各种初学者书籍。目前第一个应用程序是 纯粹是为了我在使用之前确保我理解该语言 进入上传市场的领域。不过,如果我想让它正常工作,它可能会被上传:)。
我当前遇到的问题是我的景观 main.xml 的行为 通过模拟器运行与在手机上运行时不同 (三星 Galaxy S2)。现在我知道我的手机屏幕更大了 那个模拟器,但我会认为我的设置 main.xml 会阻止编辑文本过度拉伸。
这是我的布局土地文件夹中的 main.xml 尝试 1,它是我的 Player2_name 编辑可拉伸的文本对象:
<?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>
这是我的 main.xml 尝试 2,来自我的布局区域文件夹,它是我的 Player2_name 编辑拉伸的文本对象:
<?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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我在之前的评论中所想的那样,这与我对方向处理方式的误解有关。我现在已经解决了这个问题,所以我会将其标记为已解决
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