【问题标题】:Multiple layout within one activity android一个活动中的多个布局android
【发布时间】:2015-05-06 20:42:32
【问题描述】:

在我的活动IndividualActivity 中,我设置了individual.xml 的上下文视图,现在我还想在活动中添加另一个sub_individual.xml而不删除、替换或隐藏individual.xml,这样他们仍然在一起。

public class IndividualActivity  extends Activity {
       @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.individual);            
        ...
     }
  }

individual.xml

<RelativeLayout 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"
    tools:context=".IndividualActivity"
    android:background="@drawable/default_wall" >
    <ListView
        android:id="@+id/listx"
        android:layout_width="fill_parent"
        android:layout_height="380dp"
        android:dividerHeight="1dp"/>
     ...

sub_individual.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="40dip"
    android:layout_marginLeft="0dp"
    android:background="#323331"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:paddingLeft="5dip"
    android:text="custom title bar" >

    <ImageView
        android:id="@+id/bk_btn"
        android:layout_width="35dip"
        android:layout_height="35dip"
        android:background="#DDD" />
    ...

【问题讨论】:

标签: android xml android-activity layout layout-inflater


【解决方案1】:

【讨论】:

  • 你比我早,先生。 +1。 @SlimShady 片段有据可查。 (:
  • @LittleChild 我经历过它并没有打败我,即我没明白,你能举个例子
  • @SlimShady 哦不,那个“打败我”是给 GreyBeardedPirate 先生的:D 我也打算在 Fragments 上发布答案。研究如何使用FragmentTransaction 添加新片段。这很简单
  • developer.android.com/guide/components/fragments.html 有一个很好的例子.这是一个非常有据可查的框架特性,而不是秘密。
  • @SlimShady mah man ya gotta feel me,哟。你不能只对代码进行攻击。您必须付出一些努力并敲击一些键,编写一些代码。你知道我在说什么吗?
【解决方案2】:

您可以从 xml 中使用它 在您的第一个 xml 中使用“include”标签并在此标签中添加第二个 xml。

【讨论】:

  • 哟,我为你打了+1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多