【发布时间】:2012-11-24 12:11:33
【问题描述】:
我正在尝试按照以下示例编写每周日历:
How can I create a weekly calendar view for an Android Honeycomb application?
我已经在 XML 文件中添加了一个时间标记行,该行假设在当前时间。为此,我使用:
<LinearLayout
android:id="@+id/currentTimeMarkerLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginTop="120dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="0dp" >
<View
android:layout_width="0dp"
android:layout_height="3dp"
android:layout_weight="1" />
<View
android:id="@+id/currentTimeLineView"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="14"
android:background="@color/dark_blue" />
</LinearLayout>
这个LinearLayout 在RelativeLayout 内,它们都在ScrollView 内。
我正在尝试通过编程“移动”这一行,方法是用这些行修改layout_margintTop:
int dipValue = 720; // we want to convert this dip value to pix
Resources r = getResources();
float pix = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
dipValue, r.getDisplayMetrics());
LinearLayout lay =(LinearLayout) findViewById(R.id.currentTimeMarkerLinearLayout);
LinearLayout.LayoutParams lp = lay.getLayoutParams();
lp.setMargins(0, (int) pix, 0, 0);
lay.setLayoutParams(lp);
但我在lp = lay.getLayoutParams() 中收到一个错误,告诉我它无法从ViewGroup.LayoutParams 转换为LinearLayout.LayoutParams。
我做错了什么?
【问题讨论】:
标签: java android xml android-layout