我已经阅读了很多答案来解决这个问题,但不知何故我没有找到合适的解决方案。我是初学者,可能是因为这个原因。
我正在创建一个新的 Activity B,点击 Activity A 的按钮。B 有很多 UI。所以加载大约需要 10 秒。它显示黑屏直到。
public class B extends Activity
{
Dialog dialog_sec1__participant_name;
Dialog dialog_sec1__fathers_name;
Dialog dialog_sec1_address;
.
.
.
.
//lot more
Button btn_section_preview;
Button btn_sec1_address;
.
.
//lot more
CustomObj mObject = null;
CustomObj2 mObject2 = null;
.
.
.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.B);
mObject = new CustomObj();
mObject2 = new CustomObj();
.
.
txt_sec1_preview_household_id=(TextView)findViewById(R.id.a11);
txt_sec1_preview_date_of_interview=(TextView)findViewById(R.id.a22);
txt_sec1_preview_time_of_interview=(TextView)findViewById(R.id.a33);
.
.
.
// Lot more, including setting view to Dialog.
.
.
.
// and lot of onclick listners
btn_section_preview.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
//doing my job here
}
});
.
.
.
.
此 View 中有很多 UI 组件。我现在的结构是这样的。现在,
- 如何减少加载时间?
- 如果上面的方法不是,那么什么是好的方法(实践)呢? 一个好方法。
请指导我。
最佳答案
如果您有大约 200 个从上到下排列的元素,您可以尝试使用 ListView,它会为您处理延迟加载。因此,在启动 Activity 时,您将仅加载可见元素。或者尝试使用其他方法来实现延迟加载,例如查看 ViewStub。所以这里的主要想法是划分你的布局并允许它部分加载。
关于java - 管理 Activity 加载时间的良好做法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14640523/