mgr*_*iez 3 java xml android android-layout
我正在尝试按照以下示例编写每周日历:
如何为 Android Honeycomb 应用程序创建每周日历视图?
我已经在 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>
Run Code Online (Sandbox Code Playgroud)
这LinearLayout是在 aRelativeLayout里面,它们都在 a 里面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);
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误,lp = lay.getLayoutParams()告诉我它不能从 转换ViewGroup.LayoutParams为LinearLayout.LayoutParams。
我究竟做错了什么?
但是我在 lp = layout.getLayoutParams() 中收到一个错误,告诉我它无法从 ViewGroup.LayoutParams 转换为 LinearLayout.LayoutParams。
如果 由LinearLayout包裹,而RelativeLayout不是它LayoutpParams的类型RelativeLayout.LayoutParams(子LayoutParams从父获取)。您也很可能为LayoutParams您在代码中使用的导入了错误的类。
LinearLayout lay = (LinearLayout) findViewById(R.id.currentTimeMarkerLinearLayout);
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams)lay.getLayoutParams();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2778 次 |
| 最近记录: |