我有这样的LinearLayout是一个RelativeLayout的的孩子除其他事项外一个ListView一起:如何在第一次绘制时以编程方式显示布局布局?
<LinearLayout
android:id="@+id/color_bar"
android:layout_alignParentBottom="true"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="16dp"
android:padding="0dp"
android:orientation="horizontal"
>
<TextView
android:id="@+id/space_used_bar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#006688"
android:padding="0dp"
/>
<TextView
android:id="@+id/space_free_bar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#444444"
android:padding="0dp"
/>
</LinearLayout>
我不打算把这些TextViews任何文字;他们只是在那里为他们的背景颜色值。我想以编程方式设置这两个TextView的宽度,我可以这样做,但问题是第一次显示LinearLayout时,它没有绘制。它没有大小,我也看不到其中包含的TextViews。当用户几乎做了任何事情(例如锁定屏幕,按主页按钮,单击列表项目,选择选项项目等)TextViews正常显示。只是在活动打开的第一时刻,TextViews和Layout并没有显示出来。有谁知道这个问题可能是什么?
P.S.我已经尝试在LinearLayout以及各个TextViews上调用invalidate。
编辑:这里是回调
@Override
public void onCreate(Bundle savedInstanceState)
{
//Log.d(TAG, "onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.browser);
topMenu = getActionBar();
lv = (ListView) findViewById(R.id.file_list);
spaceUsedBar = (TextView) findViewById(R.id.space_used_bar);
spaceFreeBar = (TextView) findViewById(R.id.space_free_bar);
spaceUsed = (TextView) findViewById(R.id.space_used);
spaceFree = (TextView) findViewById(R.id.space_free);
colorBar = (LinearLayout) findViewById(R.id.color_bar);
stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
if (savedInstanceState == null)
{
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
currentDirectory = externalStorageDirectory;
else
{
currentDirectory = new File(ROOT_DIR);
Toast t = Toast.makeText(c, R.string.not_mounted, Toast.LENGTH_SHORT);
t.show();
}
}
else
{
currentDirectory = new File(savedInstanceState.getString("savedPath"));
int savedPosition = savedInstanceState.getInt("savedPosition");
int savedListTop = savedInstanceState.getInt("savedListTop");
if (savedPosition >= 0)
lv.setSelectionFromTop(savedPosition, savedListTop);
}
}
@Override
public void onStart()
{
//Log.d(TAG, "onStart()");
super.onStart();
lv.setOnItemClickListener(this);
lv.setMultiChoiceModeListener(this);
browseTo(currentDirectory);
}
@Override
public void onResume()
{
//Log.d(TAG, "onResume()");
super.onResume();
}
是的,这是让我感到困惑的部分。我经历了所有的代码之间发生的时间,直到他们没有出现,而且这似乎完全是任意的。我会很快发布代码。 –