我用XML创建了以下DialogFragment:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/mainLayout"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/quoteLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<Button
android:id="@id/getMoreButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/getMore"
android:onClick="getMore" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/adLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
</LinearLayout>
我一直在使用quoteLayout部分,让它按照我的意愿执行。现在我想用一个按钮和一个广告来填充其他部分。
问题是mainLayout的其他部分仍然没有显示任何内容。屏幕的结尾是quoteLayout的结尾。
有什么想法吗?
答案 0 :(得分:3)
您将其方向设置为CREATE OR REPLACE FUNCTION custom_diff(
_from TIMESTAMPTZ, _to TIMESTAMPTZ, _custom INTERVAL, OUT amount INTEGER)
RETURNS INTEGER
LANGUAGE plpgsql
AS $function$
DECLARE
max_iterations INTEGER :=10;
t INTEGER;
BEGIN
amount:=0;
WHILE max_iterations > 0 AND NOT (
extract(EPOCH FROM _to) <= ( extract(EPOCH FROM _from) + extract(EPOCH FROM _from + _custom) ) / 2
AND
extract(EPOCH FROM _to) >= ( extract(EPOCH FROM _from) + extract(EPOCH FROM _from - _custom) ) / 2
) LOOP
-- RAISE NOTICE 'iter: %', max_iterations;
t:=EXTRACT(EPOCH FROM ( _to - _from )) / EXTRACT(EPOCH FROM _custom);
_from:=_from + t * _custom;
amount:=amount + t;
max_iterations:=max_iterations - 1;
END LOOP;
RETURN;
END;
$function$
,但在您的linearlayout子项中,您将vertical
属性设置为android:layout_height
,以填充布局。它应该是match_parent
或使用wrap_content
来更好地组织它的外观。至少,这对我来说是错误的。尝试将weights
换成match_parent
或使用wrap_content
属性。请注意,如果您使用weight
设置weight
0dp。
android:layout_height' to
答案 1 :(得分:0)
您已将报价布局设置为另一个也匹配高度的LinearLayout中的match_height。您的按钮布局和adLayout只是在屏幕底部。
要解决此问题,我会使用如下的布局权重:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/mainLayout"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/quoteLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<Button
android:id="@id/getMoreButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/getMore"
android:onClick="getMore" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/adLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:paddingLeft="5dp"
android:paddingRight="0dp"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
</LinearLayout>
请注意,我已将layout_height
更改为0dp
并添加了layout_weight
标记。此标记使您的布局将根据输入的值调整到高度的某个百分比。
你也可以使用wrap_content
作为身高。