Android: SlidingDrawer yüksekliği wrap_content ayarlanabilir?
Uygulamaya çalışıyorum SlidingDrawer
olacak işgal tam ekran genişliği, ama kimin yüksekliği belirlenir dinamik tarafından içeriği: diğer bir deyişle, standart fill_parent
düzen davranış için genişlik ve wrap_content
yüksekliği. Bu düzen XML içinde belirtilen ettim tam olarak nasıl (aşağıya bakınız) ama sürgülü çekmece her zaman tam ekran yüksekliği için açılır. Benim içerik yüksekliği değişir, ama genellikle ben bunun altında büyük bir boşluk ile sona kadar sadece yarım ekran yüksekliği. İstediğim içeriği düzgünce ekranın üzerinde oturmak için.
Aklıma bunu düzeltmek için her şeyi denedim ama hiçbir şey şimdiye kadar çalıştı. Eğer's çalışır belirli bir değeri (*8 örneğin*) 7 ** ama ihtiyacım olan bu değil: dinamik olmalı. SlidingDrawer
başım belaya girerse Tabii ki tüm alt öğeleri wrap_content
çok yükseklik ayarlı emin oldum.
SlidingDrawer belgelerine biraz bu konuda belirsiz ve ya sonra ben ne herhangi bir örnek bulmak mümkün olmamıştır. Eğer herkes yanlış gidiyorum nerede olursa gerçekten çok memnun olurum!
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ViewFlipper
android:id="@ id/ImageFlipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@ id/imageView0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop" />
<ImageView
android:id="@ id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop" />
<ImageView
android:id="@ id/imageView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop" />
</ViewFlipper>
<SlidingDrawer
android:id="@ id/infoDrawer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:handle="@ id/infoDrawerHandle"
android:content="@ id/infoDrawerContent"
android:allowSingleTap="false"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<!-- Sliding drawer handle -->
<ImageView
android:id="@id/infoDrawerHandle"
android:src="@drawable/info_handle_closed"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- Sliding drawer content: a scroller containing a group of text views
laid out in a LinearLayout -->
<ScrollView
android:id="@id/infoDrawerContent"
android:background="@drawable/info_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="false" >
<LinearLayout
android:id="@id/infoDrawerContent"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip" >
<TextView
android:id="@ id/infoTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="16dip"
android:textStyle="bold" />
<TextView
android:id="@ id/infoCreator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="14dip"
android:textStyle="italic"
android:paddingBottom="10dip" />
<TextView
android:id="@ id/infoDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="14dip"
android:paddingBottom="10dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffcc00"
android:textSize="14dip"
android:textStyle="bold"
android:text="@string/heading_pro_tip" />
<TextView
android:id="@ id/infoProTip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffcc00"
android:textSize="14dip" />
</LinearLayout>
</ScrollView>
</SlidingDrawer>
</RelativeLayout>
CEVAP
SlidingDrawer sınıf onMeasure()
yöntem, temelde layout_height="wrap_content"
çalışmıyor bu neden fill_parent
, düzen modlarını geçersiz kılar.
Bunu çözmek için, onur layout_width
layout_height
öznitelikleri yeniden hayata onMeasure()
bir yöntem ile SlidingDrawer genişletebilirsiniz. Sonra <fully.qualified.package.ClassName ...>
17 *değiştirerek XML düzeninde bu özel bir sınıf kullanabilirsiniz.
Çekmece artık üst düzen dolum olacağından, yerçekimi özniteliği çekmecenin olması gereken yerde kenarına set ile bir LinearLayout içine alın gerekir unutmayın.
Aşağıda bu amaç ve örnek bir düzen için yaratılmış bir sınıf.
WrappingSlidingDrawer sınıf :
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SlidingDrawer;
public class WrappingSlidingDrawer extends SlidingDrawer {
public WrappingSlidingDrawer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL);
mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
}
public WrappingSlidingDrawer(Context context, AttributeSet attrs) {
super(context, attrs);
int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL);
mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED) {
throw new RuntimeException("SlidingDrawer cannot have UNSPECIFIED dimensions");
}
final View handle = getHandle();
final View content = getContent();
measureChild(handle, widthMeasureSpec, heightMeasureSpec);
if (mVertical) {
int height = heightSpecSize - handle.getMeasuredHeight() - mTopOffset;
content.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, heightSpecMode));
heightSpecSize = handle.getMeasuredHeight() mTopOffset content.getMeasuredHeight();
widthSpecSize = content.getMeasuredWidth();
if (handle.getMeasuredWidth() > widthSpecSize) widthSpecSize = handle.getMeasuredWidth();
}
else {
int width = widthSpecSize - handle.getMeasuredWidth() - mTopOffset;
getContent().measure(MeasureSpec.makeMeasureSpec(width, widthSpecMode), heightMeasureSpec);
widthSpecSize = handle.getMeasuredWidth() mTopOffset content.getMeasuredWidth();
heightSpecSize = content.getMeasuredHeight();
if (handle.getMeasuredHeight() > heightSpecSize) heightSpecSize = handle.getMeasuredHeight();
}
setMeasuredDimension(widthSpecSize, heightSpecSize);
}
private boolean mVertical;
private int mTopOffset;
}
Örnek düzeni (WrappingSlidingDrawer varsayarak paket com.paketi) :
<FrameLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
... stuff you want to cover at full-size ...
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:orientation="vertical">
<com.package.WrappingSlidingDrawer android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:content="@ id/content"
android:handle="@ id/handle">
... handle and content views ...
</com.package.WrappingSlidingDrawer>
</LinearLayout>
</FrameLayout>
Android durum çubuğu yüksekliği...
İmageView android XML layout=layout_he...
Özel görünüm Android set yüksekliği ve...
Kırpma veya bozulma olmadan Android İm...
Android: ViewPager WRAP_CONTENT var ku...