为什么activity_main.xml预览和实际结果不一样?
androidstudio吧
全部回复
仅看楼主
level 2
在Android studio里面预览时这样的:
而实际在模拟器和红米(实机)跑出来,却是所有控件都挤在了左上角:
是我哪里配置的姿势不对吗?
2017年06月19日 15点06分 1
level 2
其他配置是这样
2017年06月19日 15点06分 2
level 13
初学者路过,你用什么布局的啊
2017年06月19日 15点06分 3
线性布局,通过坐标指定的,我直接创建的一个hello world的模板,然后拖了几个控件过来,不知道为什么显示和预览的不一样
2017年06月19日 15点06分
level 13
我猜可能是你没有用到任何一种布局所以控件位置是不确定的,换了分辨率就出问题了
2017年06月19日 15点06分 4
level 2
我把表现方式改了一下现在好使了
2017年06月19日 15点06分 6
level 13
回复 蛋身汉字_风凌 :我也不太清楚,布局是要自己写的,我看的教程是先讲这些布局方式,用这些布局控制控件的位置。可能你直接拖进来用的坐标,这样不同分辨率显示起来有差异,我也是初学者,知道的不多。
2017年06月19日 16点06分 7
嗯嗯,非常感谢
2017年06月19日 16点06分
level 13
我郁闷了,总是被系统删帖。。。没说什么特别的啊[泪]
2017年06月19日 16点06分 8
摸头
2017年06月21日 13点06分
level 4
<?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"
(tools这行貌似也用不到,删掉了)
android:orientation="vertical" (这里用垂直)>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"(这里用水平)>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电话号码:"//helloworld改成 电话号码:
后面一长串的几行都删了
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入电话号码"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"(水平)>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="短信内容:"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入短信内容"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"(水平)>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拨打电话"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="发送短信"/>
</LinearLayout>
</LinearLayout>
线性不用指定坐标,指定坐标貌似是绝对布局用的,现在已经弃用了。我也是初学者,跟着一个老教程学的,所以我把多余的东西都删掉了,现在就这样就能实现你想的那个布局了,直接手写,不要拖,
分析一下布局,整体是垂直线性布局,垂直的3行,然后每行都是水平的2个控件,所以最外面需要一个垂直线性布局,里面是3个水平线性,
第一个水平线性里面写一个TextView和一个EditText,第二个跟第一个一样,第三个是两个Button
但是感觉这教程学不下去了,好多代码不能用了,直接报错,还有AppCompatActivity和Activity的各种不支持;直接跑真机,渣电脑模拟器无力
每天都要上度娘查几个小时,真心蛋疼,有基于Android studio的教程的话求分享
话说你这个程序能直接拨出去么,我真机试验的时候是拨不出去的,只能到拨号界面,需要自己点击拨号键,模拟器可以直接拨通另外一个模拟器。我问了下,貌似是系统限制了
2017年06月20日 15点06分 9
level 4
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="拨打电话"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="发送短信"/>
</LinearLayout>
按钮这两个应该用权重的,搞错了,之前写了没看
2017年06月20日 15点06分 10
现在应该差不多了
2017年06月20日 15点06分
确实可以了,厉害,我是刚做安卓好多问题不懂,非常感谢![哈哈]
2017年06月21日 13点06分
@蛋身汉字_风凌 客气了,共勉,我也好多不懂
2017年06月21日 14点06分
level 2
还是用线性布局吧,那种效果你直接拖进来会有分辨率的问题的,再用线性布局的嵌套,就可以实现这样的效果,我也初学者,希望对楼主有点帮助
2017年09月15日 10点09分 11
level 5
没设定坐标
2017年09月15日 23点09分 12
level 1
你这个是约束布局,你要是不加约束,控件都会叠加在一起的
2017年09月17日 07点09分 13
1