第二个布局与展示包括在Android Studio中的标签 [英] Second layout is not showing with include tag in android studio

查看:340
本文介绍了第二个布局与展示包括在Android Studio中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了两款Android的布局应在顺序显示。这样,第一布局必须显示在网页的顶部和第二布局必须在页面的底部示出。但是,以下code只示出了第一布局。我怎样才能显示第二种布局呢?

主要布局

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>    <包括布局=@布局/ first_layout/>
    <包括布局=@布局/ second_layout/>< / LinearLayout中>

第一个XML布局

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    机器人:paddingBottom会=@扪/ activity_vertical_margin
    工具:上下文=net.simplifiedcoding.androidloginapp.UserProfile>    <的TextView
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:textAppearance =机器人:ATTR / textAppearanceLarge
        机器人:文字=大文本
        机器人:ID =@ + ID / textView3
        机器人:layout_alignParentTop =真
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentStart =真/>
< / LinearLayout中>

第二个布局

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:方向=垂直
    机器人:paddingTop =@扪/ activity_vertical_margin
    机器人:paddingBottom会=@扪/ activity_vertical_margin
    工具:上下文=MainActivity。>
<的TextView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=姓名
    机器人:ID =@ + ID / TextView的/><的EditText
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:ID =@ + ID / editTextName/><的TextView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=地址
    机器人:ID =@ + ID / textView2/><的EditText
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:ID =@ + ID / editTextAddress/><按钮
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=插入
    安卓的onClick =插入
    机器人:ID =@ + ID /键/><的TextView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:ID =@ + ID / textViewResult/>
< / LinearLayout中>


解决方案

我还不知道这是否会解决你的问题,但你可以尝试添加的android:layout_width 的android:layout_height 在包括布局,以及布局体重

 <包括布局=@布局/ first_layout
    机器人:layout_width =match_parent
    机器人:layout_height =0dp
    机器人:layout_weight =1/><包括布局=@布局/ second_layout
    机器人:layout_width =match_parent
    机器人:layout_height =0dp
    机器人:layout_weight =1/>

补充信息

为什么你有这个问题的原因是因为这两个不同的界面使用 match_parent 的高度。这意味着,在第一布局,它将匹配母体的尺寸(在这种情况下是整个屏幕),从而,所述第一布局将占据整个屏幕和第二布局就不会出现。

在此解决方案,你告诉布局都使用消耗只有屏幕的一半 layout_weight

I have designed two Android layouts which should be shown in order. So, the first layout must be showing in top of the page and the second layout must be showing in bottom of the page. However, the following code only shows the first layout. How can I show the second layout too?

the main layout is

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include layout="@layout/first_layout"/>
    <include layout="@layout/second_layout"/>

</LinearLayout>

The first xml layout is

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"     
    android:layout_width="match_parent"
    android:layout_height="match_parent"   
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="net.simplifiedcoding.androidloginapp.UserProfile">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/textView3"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</LinearLayout>

The second layout is

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"       
    android:layout_width="match_parent"
    android:layout_height="match_parent"    
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:orientation="vertical"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"      
    tools:context=".MainActivity">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Name"
    android:id="@+id/textView" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/editTextName" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Address"
    android:id="@+id/textView2" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/editTextAddress" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Insert"
    android:onClick="insert"
    android:id="@+id/button" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textViewResult" />
</LinearLayout>

解决方案

I'm not yet sure if this will solve your problem, but can you try adding android:layout_width and android:layout_height in your included layout as well as layout weight?

<include layout="@layout/first_layout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

<include layout="@layout/second_layout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

Added info

The reason why you have that problem is because both your layouts uses match_parent for the height. That means that at the first layout, it will match the size of the parent (which in this case is the whole screen), thus, the first layout will occupy the whole screen and the second layout won't appear.

In this solution, you are telling both layouts to consume only half of the screen by using the layout_weight.

这篇关于第二个布局与展示包括在Android Studio中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆