include导入布局后原有的控件不可见的解决方法
来源:互联网 发布:hp1505n网络打印设置 编辑:程序博客网 时间:2024/05/22 05:26
原activity布局文件main_activity.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:orientation="horizontal" > <EditText android:id="@+id/edittext" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> <Button android:id="@+id/button1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="button1" /> </LinearLayout>
效果图如下
然后做了一个简单的标题栏title_layout.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:orientation="horizontal" > <Button android:id="@+id/btn_back" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="返回" /> <TextView android:id="@+id/textview" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:text="this is title" android:gravity="center" /> <Button android:id="@+id/btn_edit" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="编辑" /></LinearLayout>
效果图如下
在main_activity.xml里通过include引入title_layout布局
<include layout="@layout/item_title"/>
结果运行出来是这样
检查了一下,发现title_layout布局里将android:layout_height这个属性设为了match_parent 。
这导致title_layout填满了整个屏幕
修改为wrap_content之后效果还是这样
这时我突然想起来,main_acitvity布局里原有的edittext和button都是以width属性作为权重比的:
android:layout_width=”0dp”
android:layout_height=”wrap_content”
android:layout_weight=”1”
但是main_activity布局的orientation属性是vertical,也就是说edittext和button是一上一下排列的,所以此时这两个控件都不可见了
将这两个控件的属性改为如下
android:layout_width=”wrap_content”
android:layout_height=”0dp”
android:layout_weight=”1”
效果如下
问题解决了~~~这里控件虽然显示出来了,但是不是我们想要的显示方式,这里可以在用一个orientation属性为horizontal的LinearLayout布局将这两个控件包起来
main_activity.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="wrap_content" android:orientation="vertical" > <include layout="@layout/item_title"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <EditText android:id="@+id/edittext" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" /> <Button android:id="@+id/button1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="button1" /></LinearLayout></LinearLayout>
最终效果如下
0 0
- include导入布局后原有的控件不可见的解决方法
- LinearLayout界面放置过多控件,导致下方控件不可见的解决方法:
- 关于Vuforia导入数据包后不显示图片的解决方法
- android输入法弹出后,不影响activity原有布局
- android 输入法弹出后,不影响activity原有布局
- android 问题:输入法弹出后,不影响activity原有布局
- C# picturebox 设置为不可见后 引出的问题
- 设置View的可见以及不可见
- View的可见与不可见
- 56. 让不可见的更可见
- fragment可见和不可见的方法
- fragment可见和不可见的方法
- 关于mysql版本升级后,原有的数据无法访问的解决方法,mysql错误代码:1558
- centos安装后导致原有的ubuntu无法启动的解决方法
- include过来的布局怎么找到其父控件
- EditText作为密码框,点击可见不可见按钮,实现密码的可见和不可见
- 注意不可见的字符!
- 创建不可见的Activity
- Hive1.2.1的安装过程
- 二分搜索
- cmd怎么进入d盘
- Android 4.4 Settings 应用分析
- 使用模版元编程实现C和C++中复杂类型声明的语义化
- include导入布局后原有的控件不可见的解决方法
- idea 源码
- Android代码实现新建文件夹,并将文件保存到新建的文件夹中
- 颜色传感器TCS230的使用
- 2016.3.30python函数
- jquery on方法详解
- jvm 调优中的一些概念
- 2016 从明天才开始
- 开源转场库HYBControllerTransitions