背景配置文件 \res\drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape = "rectangle">
<!-- <gradient android:angle = "270"
android:startColor = "#99ccff"
android:centerColor="#00ccff"
android:endColor = "#99ccff"/> -->
<solid android:color="#99999999" />
<corners android:topLeftRadius = "18dip"
android:topRightRadius = "18dip"
android:bottomLeftRadius = "18dip"
android:bottomRightRadius = "18dip" />
<!-- <padding android:left="50dip"
android:top="50dip"
android:right="50dip"
android:bottom="50dip"/> -->
</shape>
style文件 /res/values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name = "translucent" parent = "android:style/Theme.Dialog">
<item name="android:windowBackground">@drawable/activity_style</item>
<!-- <item name="android:windowIsTranslucent">true</item> -->
<!-- <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item> -->
</style>
</resources>
layout文件/res/layout<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="200dip"
android:layout_height="300dip" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<TextView
android:id="@+id/detail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff">
</TextView>
</ScrollView>
</LinearLayout>
代码
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
LinearLayout layout = (LinearLayout)getLayoutInflater().inflate(R.layout.showdetail, null);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
LayoutParams params = new LayoutParams((int)(dm.widthPixels*0.6), LayoutParams.WRAP_CONTENT);
Log.v("HAHA", String.valueOf(dm.widthPixels));
Log.v("HAHA", String.valueOf(dm.heightPixels));
layout.setLayoutParams(params);
setContentView(layout);
TextView tv = (TextView)findViewById(R.id.detail);
Intent intent = getIntent();
int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
SharedPreferences sp = getSharedPreferences(SettingActivity.PREF, 0);
tv.setText(sp.getString(SettingActivity.UPDATE_CONTENT + appWidgetId, null));
//tv.setText("Hello world!!!!!!!!!");
}发现窗口的大小不受代码中的new LayoutParams((int)(dm.widthPixels*0.6), LayoutParams.WRAP_CONTENT)控制,显示的内容少得时候窗口就小,仅能包含内容。显示内容多的时候,就会充满通知栏下的整个屏幕。
在背景配置文件中加入padding属性的话,也是充满通知栏下的整个屏幕,被背景颜色充斥,只是中间显示文字的部分和边缘有了padding。在layout文件中定义的android:layout_width="200dip" android:layout_height="300dip"根本没有起作用。我想要自定义窗口的大小随着不同设备分辨率的不同而不同,就像上面代码中的那样,不知道怎么就解决这个东西。求助各位大侠~!!!
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape = "rectangle">
<!-- <gradient android:angle = "270"
android:startColor = "#99ccff"
android:centerColor="#00ccff"
android:endColor = "#99ccff"/> -->
<solid android:color="#99999999" />
<corners android:topLeftRadius = "18dip"
android:topRightRadius = "18dip"
android:bottomLeftRadius = "18dip"
android:bottomRightRadius = "18dip" />
<!-- <padding android:left="50dip"
android:top="50dip"
android:right="50dip"
android:bottom="50dip"/> -->
</shape>
style文件 /res/values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name = "translucent" parent = "android:style/Theme.Dialog">
<item name="android:windowBackground">@drawable/activity_style</item>
<!-- <item name="android:windowIsTranslucent">true</item> -->
<!-- <item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item> -->
</style>
</resources>
layout文件/res/layout<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="200dip"
android:layout_height="300dip" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<TextView
android:id="@+id/detail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff">
</TextView>
</ScrollView>
</LinearLayout>
代码
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
LinearLayout layout = (LinearLayout)getLayoutInflater().inflate(R.layout.showdetail, null);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
LayoutParams params = new LayoutParams((int)(dm.widthPixels*0.6), LayoutParams.WRAP_CONTENT);
Log.v("HAHA", String.valueOf(dm.widthPixels));
Log.v("HAHA", String.valueOf(dm.heightPixels));
layout.setLayoutParams(params);
setContentView(layout);
TextView tv = (TextView)findViewById(R.id.detail);
Intent intent = getIntent();
int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
SharedPreferences sp = getSharedPreferences(SettingActivity.PREF, 0);
tv.setText(sp.getString(SettingActivity.UPDATE_CONTENT + appWidgetId, null));
//tv.setText("Hello world!!!!!!!!!");
}发现窗口的大小不受代码中的new LayoutParams((int)(dm.widthPixels*0.6), LayoutParams.WRAP_CONTENT)控制,显示的内容少得时候窗口就小,仅能包含内容。显示内容多的时候,就会充满通知栏下的整个屏幕。
在背景配置文件中加入padding属性的话,也是充满通知栏下的整个屏幕,被背景颜色充斥,只是中间显示文字的部分和边缘有了padding。在layout文件中定义的android:layout_width="200dip" android:layout_height="300dip"根本没有起作用。我想要自定义窗口的大小随着不同设备分辨率的不同而不同,就像上面代码中的那样,不知道怎么就解决这个东西。求助各位大侠~!!!
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@color/tec</item>
来取消默认的背景和frame。
然后添加一个view来控制大小。即:通过设定view的宽高来控制弹窗口的大小。