有关Android线性布局的问题

系统提醒中 2019-03-15 10:11:57
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.MainFragment"
android:orientation="horizontal">
<TextView
android:id="@+id/text_one"
android:layout_width="30dp"
android:layout_height="match_parent"
android:text="TextView"
android:textColor="#000000"
android:textSize="5sp"
android:background="#3C8DC4"/>

<TextView
android:id="@+id/text2"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
android:text="TextView"
android:textColor="#000000"
android:textSize="5sp"
android:background="#3C8"/>

</LinearLayout>

这段代码哪出问题了,本来是要求text1和text2水平分布,但是结果是text2覆盖掉了text1;使用的Android studio,而且不能用Android:layout_toRightOf这个语法
...全文
673 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fei得更高 2019-03-20
  • 打赏
  • 举报
回复
貌似代码是没有什么问题的
Woo_home 2019-03-19
  • 打赏
  • 举报
回复
看了一下你的代码,应该是OK的
  • 打赏
  • 举报
回复
有个属性叫weight,即权重。会按照权重设置比例,比如说四个button的权重都是1,那么每个大小占25%
胡牧 2019-03-19
  • 打赏
  • 举报
回复
代码没问题吧,toRightOf是RelativeLayout用的。
IGetYouu 2019-03-16
  • 打赏
  • 举报
回复
Android:layout_toRightOf 线性布局不可以使用,相对布局可以使用

代码是没问题的,你确定你引用的是这个布局吗?是不是引用别的布局去了,只是同名
亲爱的Joe 2019-03-16
  • 打赏
  • 举报
回复
我看很正常啊,蓝色的是textview1,绿色的是textview2,2 marginLeft=30dp,哪里覆盖了
丶Chao 2019-03-15
  • 打赏
  • 举报
回复
用你的代码跑了一下 没有问题啊
模拟机效果


activety_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="horizontal">

<TextView
android:id="@+id/text_one"
android:layout_width="30dp"
android:layout_height="match_parent"
android:text="TextView"
android:textColor="#000000"
android:textSize="5sp"
android:background="#3C8DC4"/>

<TextView
android:id="@+id/text2"
android:layout_width="30dp"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
android:text="TextView"
android:textColor="#000000"
android:textSize="5sp"
android:background="#3C8"/>

</LinearLayout>



80,354

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧