viewStub

RelativeLayout and ViewStub inflation

China☆狼群 提交于 2020-06-24 08:31:15
问题 I have the following layout. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/list_item_bottom"> <TextView android:id="@+id/list_item_name" android:layout_width="match_parent" android:layout_height="wrap_content"/> <ViewStub android:id="@+id/stub_for_alt_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout

RelativeLayout and ViewStub inflation

风流意气都作罢 提交于 2020-06-24 08:30:29
问题 I have the following layout. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/list_item_bottom"> <TextView android:id="@+id/list_item_name" android:layout_width="match_parent" android:layout_height="wrap_content"/> <ViewStub android:id="@+id/stub_for_alt_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout

从源码角度深入理解LayoutInflater

两盒软妹~` 提交于 2020-02-02 00:14:24
关于LayoutInflater,在开发中经常会遇到,特别是在使用ListView的时候,这个几乎是必不可少。今天我们就一起来探讨LayoutInflater的工作原理。 一般情况下,有两种方式获得一个LayoutInflater实例: LayoutInflater inflater1, inflater2; inflater1 = LayoutInflater.from(this); inflater2 = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 但是当我们查看源码的时候,却发现这两种其实是一种,只不过第一种将第二种封装了一下,我们看看from这个方法的源码: /** * Obtains the LayoutInflater from the given context. */ public static LayoutInflater from(Context context) { LayoutInflater LayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (LayoutInflater == null) { throw new

从源码角度深入理解LayoutInflater

蓝咒 提交于 2020-02-02 00:11:15
关于LayoutInflater,在开发中经常会遇到,特别是在使用ListView的时候,这个几乎是必不可少。今天我们就一起来探讨LayoutInflater的工作原理。 一般情况下,有两种方式获得一个LayoutInflater实例: LayoutInflater inflater1, inflater2; inflater1 = LayoutInflater.from(this); inflater2 = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 但是当我们查看源码的时候,却发现这两种其实是一种,只不过第一种将第二种封装了一下,我们看看from这个方法的源码: /** * Obtains the LayoutInflater from the given context. */ public static LayoutInflater from(Context context) { LayoutInflater LayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (LayoutInflater == null) { throw new

How to use LayoutInflater / ViewStub for an overlay

风流意气都作罢 提交于 2020-01-13 05:01:07
问题 As I am actually not very confident with programatically changing Views, I have following problem: At the first start of my app, I want to have an overlay for the main screen, that tells the user to have a look at the settings, as there are two critical options the user has to configure. I don't want to use an AlertDialog and rather not use a wizard. So, I decided to take an approach similar to Go SMS and create an overlay at the first start. The mockup I created looks like this: Normal menu:

Android学习笔记31:使用惰性控件ViewStub实现布局动态加载

时光怂恿深爱的人放手 提交于 2020-01-10 23:51:16
  在Android开发中,经常会遇到这样的情况,在程序运行过程中动态的根据当前条件来决定是否显示某个控件或布局,这时就可以使用惰性控件ViewStub来方便的完成这一功能。   惰性控件ViewStub是一个轻量级的View,可以实现动态布局加载。ViewStub对象是一个看不见的,零大小的视图,并在程序运行时根据需要进行动态加载。只有当ViewStub对象被设置为可见,或是调用了ViewStub.inflate()方法时,ViewStub对象所指向的布局才会被实例化,并加载到指向的父布局中。这样,便通过惰性控件ViewStub实现了动态加载某个控件或布局。   在本篇博文中,我们将通过一个实例来演示如何使用惰性控件ViewStub完成动态加载布局操作。完成后的程序运行效果如图1所示。 图1 主界面显示效果   在如图1所示的主界面中,点击“展开宝贝详细描述”按钮,将通过惰性控件ViewStub加载动态布局的方式,引入一段对商品的文字描述信息,如图2所示。 图2 动态加载布局效果   从图2可以看出,通过使用惰性控件ViewStub,我们在原布局中动态的加入了一段有关商品的描述信息。当点击“隐藏宝贝详细描述”按钮时,这段商品描述信息将被隐藏,主界面将重新变为图1所示的显示效果。   下面就来说说该实例的具体实现方法。 1.静态加载布局  

NullPointerException when using ListView inside a ViewStub

为君一笑 提交于 2019-12-23 23:17:03
问题 I'm trying to create a ListView inside a ViewStub, but i keep on getting a NullPointerException . My Buttons works as intended inside the ViewStub. The code that fails is as following: else if(v.getId() == R.id.comments_button_series_view){ if(stubUsed == false){ stub = (ViewStub) findViewById(R.id.stub); View inflatedStub = stub.inflate(); String[] comments = new String[]{"comment1", "comment2"}; commentsAdapter = new ArrayAdapter<String>(this, R.layout.patient_list_element, R.id.comments

ViewStub vs. View.GONE

萝らか妹 提交于 2019-12-22 01:42:43
问题 As far as I undestand, neither a ViewStub nor a View that's GONE participate in the measure and layout passes (or rendering anyway). Is there a difference in rendering performance? What's the best practice about when to use which? 回答1: The rendering performance comes into picture when you are inflating the views. My guess is that its much cheaper to inflate a ViewStub than to inflate a View, either from XML or by changing visibility. ViewStub is especially used when you need to add/remove

Is there a way to use a ViewStub inside a RecyclerView?

走远了吗. 提交于 2019-12-21 18:30:16
问题 i'm new to android, I've been working on a project, and in my news feeds page, I'm trying to include a modular feed RecyclerView, which shows a question with different answer forms, varrying according to the Question type. The way I was doing it so far was by using the include and turning the forms visible when needed. recently since i added more modules, the app started to slowdown segnificantly, so i'm trying to implement ViewStubs. This is my RecyclerView adapter: public class

Android Data Binding - how to use ViewStub with data binding

柔情痞子 提交于 2019-12-20 18:07:08
问题 Is there anyway to use viewStubs with dataBinding ? can ViewStubProxy help ? My stub current looks like this: <ViewStub android:id="@+id/stub_import" android:inflatedId="@+id/panel_import" android:layout="@layout/progress_overlay" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="@{myobject.bottom ? bottom:top}" /> But this layout will be replaced when i inflate the viewStub so how can ViewStubs be used with android dataBinding ? this is what i