首页 新闻 赞助 找找看

求大神解决:android控件scrollview里添加自定义view的显示问题

0
悬赏园豆:100 [已关闭问题] 关闭于 2015-12-16 19:17

想做一个课程表,但是无法实现像超级课程表种那种滑动效果。

用ondraw方法实现一个自定义view,高度为宽度的2倍。想把它加到scrollview中,下面这样加不显示该view

<LinearLayout 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"
tools:context=".MainActivity"
android:orientation="vertical"
android:weightSum="35">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="horizontal"

>
</LinearLayout>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
android:layout_weight="30">

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<com.example.android_draw.Mydraw
android:id="@+id/mydraw1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:orientation="vertical" >
</LinearLayout>

</LinearLayout>

一种方法更改如下代码所示,会显示但缺乏适应屏幕高度的能力,屏幕高大于800dp时就不能用该方法啦。

<com.example.android_draw.Mydraw
android:id="@+id/mydraw1"
android:layout_width="wrap_content"
android:layout_height="800dp" />

第二种方法在view里添加如下方法。(不知道如何设置宽度为屏幕宽度)

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

setMeasuredDimension(240,319);//直接定义宽度和高度,
}

请各位大神指点一下。

Eternal_memory的主页 Eternal_memory | 菜鸟二级 | 园豆:202
提问于:2015-12-15 21:29
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册