デバイスのリストをユーザーに表示するTheme.Dialogアクティビティがあります。アクティビティは、動的に作成されたArrayAdapterを備えたListViewを使用して、デバイスのリストを表示します。ただし、何らかの理由で、ListView(およびアクティビティ自体)のサイズが変更されて、コンテンツが正しくラップされていません。代わりに、画面の約半分の幅が設定されているかのように機能します(これは、画面サイズが異なるデバイス間で持続します)。しかし、これがどこに設定されているかを理解することはできません。
誰かが私が欠けているものを見ることができますか?(私は次のコードから無関係なビットを取り除こうとしました)
これが私の活動です:
public class DeviceListActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Setup the window
setContentView(R.layout.device_list);
// Initialize array adapters
mPairedDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);
// Find and set up the ListView for paired devices
ListView pairedListView = (ListView) findViewById(R.id.paired_devices);
pairedListView.setAdapter(mPairedDevicesArrayAdapter);
//the following doesn't do anything
//getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
mPairedDevicesArrayAdapter.add("asdfasdfa");
}
}
これがdevice_list.xmlです:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@id/paired_devices"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:stackFromBottom="true"
android:background="#0000FF"/>
<!-- the colour shows the listview stretching wider than the text it contains -->
</LinearLayout>
これが私のAndroidManifest.xmlの関連部分です:
<activity
android:name=".DeviceListActivity"
android:configChanges="keyboardHidden|orientation"
android:label="too wide"
android:theme="@android:style/Theme.Dialog">
</activity>
そして、これがdevice_name.xmlです(これはArrayAdapterを初期化するために使用されます:
<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5.0dip"
android:textSize="18.0sp" />
そして、あなたが今まで質問を読み続けることに固執しているなら、私はすでに感謝しています。
最終結果は次のとおりです(アプリの残りの部分をバックグラウンドで表示します)。