麻烦我的应用程序布局 [英] Trouble with Layout of my App

查看:147
本文介绍了麻烦我的应用程序布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我解决这个问题:

XML code:

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

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="16dp"
    tools:listitem="@android:layout/simple_spinner_dropdown_item" />

</LinearLayout>

这是我的应用程序的main.xml中code。在code已经从相对改变的LinearLayout

this is the main.xml code of my app. The code has been changed from Relative to LinearLayout

推荐答案

使用LayoutInflator和膨胀意见,您的主视图时,在微调不同的值进行选择。

Use LayoutInflator and inflate views to your main view when different values in the spinner are chosen.

//主要布局

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/main_layout_id">

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="16dp"
    tools:listitem="@android:layout/simple_spinner_dropdown_item" />

<LinearLayout 
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/insert_Layout">
</LinearLayout>

</LinearLayout>

//布局2

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:id="@+id/layout_item_id">

    <TextView android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="Hello, this is the inflated text :D"
              android:layout_gravity="center"
              android:gravity="center_horizontal"
              android:id="@+id/text_item_id"/>
</LinearLayout>

//调用的XML主要布局

//call the main layout from xml

linearLayout inset_layout= (LinearLayout)findViewById(R.id.insert_Layout);

/创建一个视图吹大layout_item(与之前创建的TextView中的XML)

/create a view to inflate the layout_item (the xml with the textView created before)

View view = getLayoutInflater().inflate(R.layout.layout_item, mainLayout,false);

//添加到邮件布局

//add to the mail layout

mainLayout.addView(view);

希望这有助于:)

Hope this helps :)

这篇关于麻烦我的应用程序布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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