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

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

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

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">

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="2"

android:orientation="horizontal"

>

android:id="@+id/scrollView1"

android:layout_width="match_parent"

android:layout_height="0dp"

android:fillViewport="true"

android:layout_weight="30">

android:id="@+id/linearLayout1"

android:layout_width="match_parent"

android:layout_height="wrap_content" >

android:id="@+id/mydraw1"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="3"

android:orientation="vertical" >

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

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);//直接定义宽度和高度,

}

请各位大神指点一下。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值