【问题标题】:Programmatically add a new layout inside a SwipeView以编程方式在 SwipeView 中添加新布局
【发布时间】:2011-10-02 13:29:52
【问题描述】:

我将尝试以非常清晰易懂的方式解释我的问题。

我目前在这里使用 SwipeView:http://jasonfry.co.uk/?id=23

<uk.co.jasonfry.android.tools.ui.SwipeView  
    android:id="@+id/swipe_view"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content">
                <View android:id="@+id/view1" />
                <View android:id="@+id/view2" />
                <View android:id="@+id/view3" />
</uk.co.jasonfry.android.tools.ui.SwipeView>

这很简单,功能强大,当然工作正常。

我现在想要实现的是在这个 SwipeView 中以编程方式添加我的一些布局。

我现在有:

    SwipeView svmain=(SwipeView) findViewById(R.id.svmain);
    //View v= findViewById(R.layout.anylayout);
    svmain.addView(v);

这会崩溃,因为我要添加的 xml 不在我的主布局中。

有什么想法吗?

【问题讨论】:

    标签: android layout view swipeview


    【解决方案1】:

    刚刚找到答案:

        SwipeView svmain=(SwipeView) findViewById(R.id.svmain);
        LayoutInflater inflater = (LayoutInflater)   getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        View view = inflater.inflate(R.layout.header, null);
        svmain.addView(view);
        View view2 = inflater.inflate(R.layout.header, null);
        svmain.addView(view2);
        View view3 = inflater.inflate(R.layout.header, null);
        svmain.addView(view3);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-04
      • 2014-04-22
      • 2015-02-08
      • 2017-07-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多