小编mgr*_*iez的帖子

类型不匹配:无法从 ViewGroup.LayoutParams 转换为 LinearLayout.LayoutParams

我正在尝试按照以下示例编写每周日历:
如何为 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, …
Run Code Online (Sandbox Code Playgroud)

java xml android android-layout

3
推荐指数
1
解决办法
2778
查看次数

标签 统计

android ×1

android-layout ×1

java ×1

xml ×1