Android 添加视图直到没有更多空间
我正在尝试建立一个RPN计算器 键盘可以很好地收缩和拉伸,因此我想在视图中添加堆栈行(蓝色选择) 直到屏幕/视图上没有更多空间 第一行的xml,其容器为Android 添加视图直到没有更多空间,android,android-layout,Android,Android Layout,我正在尝试建立一个RPN计算器 键盘可以很好地收缩和拉伸,因此我想在视图中添加堆栈行(蓝色选择) 直到屏幕/视图上没有更多空间 第一行的xml,其容器为 <LinearLayout android:id="@+id/stackLayout" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_gravity="bottom|fill_vertical"
<LinearLayout
android:id="@+id/stackLayout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_gravity="bottom|fill_vertical"
android:layout_weight="1"
android:gravity="bottom"
android:orientation="vertical" >
<!-- Stack row -->
<LinearLayout
android:id="@+id/stackRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
>
<!-- Row index -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1:"
style="@style/text_style" />
<!-- Value -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|right"
android:singleLine="true"
android:text="0"
style="@style/text_style" />
</LinearLayout>
</LinearLayout>
stackView始终将其高度报告为0。这场争吵也是如此。
我哪里做错了
我已尝试将其移动到onStart、onResume和onPostResume,结果相同。据我所知,视图尚未在oncreate中呈现?也许在简历中是?我需要在创建时添加到我的活动中:
new AnInnerSillyWaitToCompleteLayoutClass().execute((Void[]) null);
然后在我的活动中,我有一个:
class AnInnerSillyWaitToCompleteLayoutClass extends AsyncTask<Void, Void, Void>
protected Void doInBackground(Void... voids) {
sleep a little while
protected void onPostExecute(Void result) {
Here the layout is complete and the dynamic
dimensions can be calculated.
class AnnirlyWaitToCompleteLayoutClass扩展了异步任务
受保护的空位背景(空位…空位){
睡一会儿
受保护的void onPostExecute(void结果){
这里的布局是完整的和动态的
可以计算尺寸。
编辑:正确的方法是侦听布局更改,并在布局完成后执行这些操作。它们在OnCreate、OnStart和OnResume中生成0。
new AnInnerSillyWaitToCompleteLayoutClass().execute((Void[]) null);
class AnInnerSillyWaitToCompleteLayoutClass extends AsyncTask<Void, Void, Void>
protected Void doInBackground(Void... voids) {
sleep a little while
protected void onPostExecute(Void result) {
Here the layout is complete and the dynamic
dimensions can be calculated.