2012-01-22 6 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에 머물러야합니다.

그래서 base (pro) 코드에서 저는 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으로 설정하려고해도 작동하지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

가 BTW 내가이 된 setContentView (R.id.main)

답변

0

으 으윽을 할 직후 크기를 설정, 그것은 AndroidAnnotations 처리 일이었다. 어떤 이유로 인해 onCreate 메서드 에서처럼 레이아웃 변경 사항을 선택하지 못하고 postOnCreate 메서드에 배치해야했습니다. 그건 어딘가에서 의사가 될 수도 있지만, 나는 그것을 놓쳤다. 계속하다