2011-08-15 8 views
0

唯一の解決策はAbsoluteLayout(特定の位置で何かを表示すること)を使用しているという問題に遭遇しました。問題のコピーAbsoluteLayout - com.android.internal.Rは解決できません

私はAbsoluteLayoutクラスをコピーして、将来のリリースで削除されず、アプリケーションが動作しなくなるのを避けようとしています。

私はここからコピーしています:http://www.google.com/codesearch#cZwlSNS7aEw/frameworks/base/core/java/android/widget/AbsoluteLayout.java&exact_package=android&q=AbsoluteLayout&type=cs

しかし、このコードを取得し、第一、私はgetPadding(方向)にすべてmPadding(方向)に変更しましたが、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 

これらの値はどのように取得できますか?または、誰かがすでに独立してこのクラスを持っていて、Googleに所属してAPIを使いたいと望んでいない場合は、

答えて

8

あなたがattrs.xmlからdeclare-styleableエントリをコピーする必要があります。

<declare-styleable name="AbsoluteLayout_Layout"> 
    <attr name="layout_x" format="dimension" /> 
    <attr name="layout_y" format="dimension" /> 
</declare-styleable> 

ちょうどあなたのアプリケーションへ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(); 
} 
+0

のTy!これは完全に機能します。 –

関連する問題