Mar*_*los 0 android android-layout
我遇到了一个问题,唯一的解决方案是使用AbsoluteLayout(只是为了在特定的位置展示一些东西).
我正在尝试复制AbsoluteLayout类,以避免在将来的版本中删除它,我的应用程序停止工作.
我正在从这里复制:http://www.google.com/codesearch#cZwlSNS7aEw/frameworks/base/core/java/android/widget/AbsoluteLayout.java&exact_package=android&q=AbsoluteLayout&type=cs
但是获取此代码,首先,我将所有mPadding(Direction)更改为getPadding(Direction),但LayoutParams构造函数仍然存在错误:
public LayoutParams(Context c, AttributeSet attrs) {
super(c, attrs);
TypedArray a = c.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.AbsoluteLayout_Layout);
x = a.getDimensionPixelOffset(
com.android.internal.R.styleable.AbsoluteLayout_Layout_layout_x, 0);
y = a.getDimensionPixelOffset(
com.android.internal.R.styleable.AbsoluteLayout_Layout_layout_y, 0);
a.recycle();
}
com.android.internal.R cannot be resolved to a variable
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得这些价值?或者有人已经拥有这个不属于谷歌的类,希望继续使用API?
您需要复制以下declare-styleable
条目attrs.xml
:
<declare-styleable name="AbsoluteLayout_Layout">
<attr name="layout_x" format="dimension" />
<attr name="layout_y" format="dimension" />
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)
只需将res/values/attrs.xml
文件添加到您的应用程序并复制到那里的行.
完成后,更新您的代码以R
从包中引用:
import com.your.package.R;
...
public LayoutParams(Context c, AttributeSet attrs) {
super(c, attrs);
TypedArray a = c.obtainStyledAttributes(attrs,
R.styleable.AbsoluteLayout_Layout);
x = a.getDimensionPixelOffset(
R.styleable.AbsoluteLayout_Layout_layout_x, 0);
y = a.getDimensionPixelOffset(
R.styleable.AbsoluteLayout_Layout_layout_y, 0);
a.recycle();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3632 次 |
最近记录: |