我嘗試創建自定義ScrollView
,它將有屬性max_height
,但我面臨的問題。當我設置自定義height
時,ScrollView
不顯示TextView
。
精簡版的版本我的代碼:
佈局:
TextView不會顯示在自定義滾動視圖
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.scrollviewtest.ExpandScrollView
android:id="@+id/scrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#Fe6" >
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView TextView TextView TextView TextView" />
</com.example.scrollviewtest.ExpandScrollView>
ExpandScrollView.java
public class ExpandScrollView extends ScrollView {
public ExpandScrollView(Context context) {
super(context);
}
public ExpandScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
setMeasuredDimension(widthSize, 180);
}}
所以,我該怎麼辦錯了嗎?
我擴展'ScrollView'和'OnMeasure()'會有一些邏輯,它改變'height' – Dima