在tablelayout中不能嵌套linearlayout么?

来源:互联网  时间:2016/4/27 20:58:12

关于网友提出的“在tablelayout中不能嵌套linearlayout么?”问题疑问,本网通过在网上对“在tablelayout中不能嵌套linearlayout么?”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题:在tablelayout中不能嵌套linearlayout么?
描述:

下面是我的代码,就在最后红色的地方加入linearlayout,加载到模拟器之后就会出现程序关闭的提示,这是怎么回事?莫非是在tablelayout中不能嵌套linearlayout?还是我的方法不对?谢谢各位大牛啦~


    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5px"
    android:stretchColumns="1"
    >
<>
        android:id="@+id/title"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/title"
    android:gravity="center_horizontal"
    android:padding="5px"
    />

<>
        android:id="@+id/name"
        android:text="@string/name"
        android:padding="5px"
        />
<>
        android:id="@+id/ename"
        android:padding="15px"
        />


<>
        android:id="@+id/code"
        android:text="@string/code"
        android:padding="5px"
        />
<>
        android:id="@+id/ecode"
        android:padding="15px"
        android:password="true"
        />


<>
        android:id="@+id/gender"
        android:text="@string/gender"
        />

<>
        android:id="@+id/male"
        android:text="@string/male"
        />
<>
        android:id="@+id/female"
        android:text="@string/female"
        />



<>
        android:id="@+id/favor"
        android:text="@string/favor"
        />
<>
        android:id="@+id/run"
        android:text="@string/run"
        />
<>
        android:id="@+id/swim"
        android:text="@string/swim"
        />

<>
        android: orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
<>
        android:id="@+id/cancle"
        android:text="@string/cancle"
        android:layout_weight="1"
        />
<>
        android:id="@+id/yes"
        android:text="@string/yes"
        android:layout_weight="1"
        />


解决方案1:



  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:padding="5px"
  android:stretchColumns="1"
  >
<>
  android:id="@+id/title"
  android:layout_width="fill_parent"  
  android:layout_height="wrap_content"  
  android:text="title"
  android:gravity="center_horizontal"
  android:padding="5px"
  />

<>
  android:id="@+id/name"
  android:text="name"
  android:padding="5px"
  />
<>
  android:id="@+id/ename"
  android:padding="15px"
  />


<>
  android:id="@+id/code"
  android:text="code"
  android:padding="5px"
  />
<>
  android:id="@+id/ecode"
  android:padding="15px"
  android:password="true"
  />


<>
  android:id="@+id/gender"
  android:text="gender"
  />

<>
  android:id="@+id/male"
  android:text="male"
  />
<>
  android:id="@+id/female"
  android:text="female"
  />



<>
  android:id="@+id/favor"
  android:text="favor"
  />
<>
  android:id="@+id/run"
  android:text="run"
  />
<>
  android:id="@+id/swim"
  android:text="swim"
  />

<>
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<>
android:id="@+id/cancle"
android:layout_width="wrap_content"  
android:layout_height="wrap_content"  
android:text="cancle"
android:layout_weight="1"
/>
<>
android:id="@+id/yes"
android:layout_width="wrap_content"  
android:layout_height="wrap_content"
android:text="yes"
android:layout_weight="1"
/>


找到原因了,是linearlayout中的button没有设置width和height属性,加上这个两个属性就可以了。
我刚才的时候只是预览有效果,没有在模拟器里允许。刚才允许报错,看logcat里提示才知道。

上一篇求一个百度站长平台邀请码
下一篇android 同一个Activity动态显示不同内容
明星图片
相关文章
《在tablelayout中不能嵌套linearlayout么?》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)