Почему работает только мой xml-макет и имеет приоритет над кодом внутри OnCreate? Я пытаюсь сделать изображение видимым/невидимым, но только макет может это сделать, знаете ли вы, почему?приоритет android приоритета макета и отсутствие реакции от кода? (видимый/невидимый на imgView)
Это просто LinearLayout вертикали:
<ImageView
android:id="@+id/friendsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:src="@drawable/friends_button" />
Весь XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="86dp"
android:layout_marginTop="10dp"
android:orientation="vertical"
>
<TextView
android:id="@+id/textRequest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<ImageView
android:id="@+id/playButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/play_button" />
<ImageView
android:id="@+id/friendsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:src="@drawable/friends_button" />
</LinearLayout>
</RelativeLayout>
и friendsButton.setVisibility(View.INVISIBLE);
в OnCreate
Я пытался поставить его невидимым в макете и Visible в код, но все тот же приоритет для макета ...
Любая идея?
Благодаря
EDIT:
Так что это OnCreate метод в моей деятельности:
public class MainActivity extends Activity {
private UiLifecycleHelper fbUiLifecycleHelper;
private ImageView playButton;
private ImageView friendsButton;
private TextView textRequest;
// Parameters of a WebDialog that should be displayed
private WebDialog dialog = null;
private String dialogAction = null;
private Bundle dialogParams = null;
LayoutInflater inflater;
private boolean gameLaunchedFromDeepLinking = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final LayoutInflater factory = getLayoutInflater();
final View v = factory.inflate(R.layout.activity_main, null);
textRequest = (TextView)v.findViewById(R.id.textRequest);
playButton = (ImageView)v.findViewById(R.id.playButton);
playButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
onPlayButtonTouched();
return false;
}
});
friendsButton = (ImageView)v.findViewById(R.id.friendsButton);
friendsButton.setVisibility(View.INVISIBLE);
friendsButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
onFriendsButtonTouched();
return false;
}
});
Здесь нет приоритетов. Файл макета используется для инициализации параметров для представлений. Как только инфляция будет завершена, параметры, которые вы вводите в код (например: 'friendsButton.setVisibility (View.INVISIBLE)'), вступят в силу. Не знаете, почему вы видите это несоответствие. Можете ли вы опубликовать свой код активности? – Vikram
@vikram спасибо, я редактировал свой пост с кодом метода OnCreate, любой идеи? – Paul