Я пытаюсь создать собственный диалог в Android.Но что бы я ни пытался сделать, я не могу изменить ширину диалога.Это просто остается прежним.Ниже приводится представление, которое я устанавливаю в качестве содержимого для диалога.
<RelativeLayout
android:id="@+id/current_stats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible">
<ImageView android:id="@+id/player_image"
android:src="@drawable/person"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
<TextView
android:id="@+id/player_name"
android:layout_below="@id/player_image"
android:layout_centerHorizontal="true"
android:text="Raja Ram"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageButton android:id="@+id/dialog_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:background="#00000000"
android:src="@drawable/close_button_selector"/>
<ImageButton android:id="@+id/dialog_flip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:background="#00000000"
android:src="@drawable/rotate"/>
</RelativeLayout>
Как видите, везде я использую wrap_content в этом примере кода.Также я попробовал следующие варианты
1) Установка собственного стиля при создании Диалога, подобного этому.
dialog = new Dialog(this,R.style.Theme_Dialog);
И стиль следующим образом
<resources>
<style name="Theme" parent="android:Theme">
</style>
<style name="Theme.Dialog">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
</resources>
2) Установка параметров для представления в onCreateDialog (), как это
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.player_info, null, false);
ViewGroup.LayoutParams p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
dialog.setContentView(v,p);
3)также попытался установить параметры Window, как это в методе onCreateDialog ()
WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width=WindowManager.LayoutParams.WRAP_CONTENT;
dialog.getWindow().setAttributes(params);
Но опять не повезло.Может кто-нибудь помочь мне с этим вопросом.Я делаю что-то неправильно??Также, можете ли вы предложить мне, как установить позиции x и y для диалогового окна?
Спасибо