2012-01-22 8 views
0

広告を無料で追加するアプリがありますが、私は自分のコードに最小限の変更を加えたいと思っていました。だから私のレイアウトで、私はこれをしなかった:Android、RelativeLayout、動的に要素を追加する

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:id="@+id/mainLayout" 
android:layout_width="fill_parent" android:layout_height="0dip" 
android:orientation="vertical" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"> 

<FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/adFrameLayout" android:background="@android:color/white"> 

</FrameLayout> 
<LinearLayout android:id="@+id/buttonGrp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" 
    android:layout_below="@id/adFrameLayout" android:orientation="horizontal"> 
    <Button android:id="@+id/normalGameBtn" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:text="@string/normalGame"/> 
    <Button android:id="@+id/shareBtn" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:text="@string/shareButton"/> 
</LinearLayout> 

<RadioGroup android:id="@+id/aiRadioGrp" android:layout_below="@id/buttonGrp" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:checkedButton="@+id/normalAI" android:layout_gravity="center_horizontal"> 
    ... 
</RadioGroup> 
<ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/aiRadioGrp"> 
    <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" 
     android:text="@string/description" android:textSize="16dip" 
     /> 
</ScrollView> 

だから、私がしたいことはあること私はそれが、無料版であれば、それは広告を表示したいと有料の場合は一番上にあるでframeLayout(adFrameLayout)サイズは0のままでなければなりません。

したがって、私はGuiceを使ってonCreateで余分な処理を行うオブジェクトを挿入します。

@Override 
public void accept(Activity activity) { 
    FrameLayout frame = (FrameLayout) activity.findViewById(R.id.adFrameLayout); 
    frame.getLayoutParams().height = 20; 
    frame.invalidate(); 
} 

これは、それはそれはしない、うまくいくことを確認するための一例であり、でframeLayoutが0のサイズにとどまる:プロバージョンでは、コードは、無料版では、私はこれをやって、何もしませんコード内で動的にサイズを変更するにはどうすればよいですか?もちろん、xmlで20pxを指定するとうまくいきますが、有料版ではサイズを0に設定しようとするとどちらもうまくいきません。私は間違って何をしていますか?私はsetContentView(R.id.main)

答えて

0

Ugghhを行った後

はところで、私はサイズ権を設定し、それがAndroidAnnotationsを扱ったものでした。何らかの理由で、onCreateメソッドのようなレイアウト変更を受け取りません。そのため、postOnCreateメソッドに配置する必要がありました。それはどこかでdoc'edされているかもしれませんが、私はそれを逃した。キャリーオン

関連する問題