小编eig*_*tx2的帖子

关闭主窗口时WPF应用程序不关闭

我习惯于Visual Studio中的WinForms编程,但我想尝试一下WPF.

我为我的项目添加了一个名为Window01的窗口.主窗口称为MainWindow.在public MainWindow()构造函数之前,我声明了Window01:

Window01 w1;
Run Code Online (Sandbox Code Playgroud)

现在我将实例化此窗口:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    w1 = new Window01();            
}
Run Code Online (Sandbox Code Playgroud)

我有一个按钮,显示窗口:w1.ShowDialog();.

这里的"有趣"事实是,如果我启动应用程序(使用调试)并在几秒钟之后退出它(我在应用程序中没有做任何事情),Visual Studio不会停止调试,就好像应用程序是仍在运行.

如果我将行移动w1 = new Window01();到按钮单击方法,意思就在上面ShowDialog(),Visual Studio的行为正常 - 也就是说,当我退出应用程序时调试停止.

为何这种奇怪的行为?

c# wpf window visual-studio-2010

68
推荐指数
3
解决办法
6万
查看次数

从另一个应用程序调用应用程序

在这个应用程序我正在开发我需要加载/调用已安装在手机上的另一个应用程序.这是一个仅供我个人使用的应用程序,因此无需检查是否安装了其他应用程序 - 我知道它是.

我已经用谷歌搜索了这个问题几个小时,但我发现任何有效的东西.主要是因为查找包名和类名的指南非常糟糕.

通过cmd和adb我能够找到关于我想要调用的应用程序的信息是:package:/data/app/com.soundcloud.android-1.apk=com.soundcloud.android(这正是它的内容)在cmd窗口说.)

我试过这样的事情:

Intent i = new Intent();
i.setClassName("/data/app/com.soundcloud.android-1.apk", "com.soundcloud.android");
startActivity(i);
Run Code Online (Sandbox Code Playgroud)

但我的应用程序只是崩溃了.我使用上面的代码,因为有人说这可以调用一个应用程序:

Intent i = new Intent();
i.setClassName("<package_name>","<Class Name(with package name)>");
startActivity(i);
Run Code Online (Sandbox Code Playgroud)

有谁知道要写什么?

PS:我自己的应用程序不需要任何有关被叫应用程序中发生的事情的信息.

android phone-call android-intent

20
推荐指数
1
解决办法
3万
查看次数

SQLiteDatabase:仅在值不存在时插入(不通过原始SQL命令)

我知道有一个SQL命令是这样的:IF NOT EXISTS但是因为Android的SQLiteDatabase类有一些很好的方法,我想知道如果通过方法不存在它是否可以插入一个值.

目前我正在使用它来插入一个String:

public long insertString(String key, String value) {
    ContentValues initialValues = new ContentValues();
    initialValues.put(key, value);
    return db.insert(DATABASE_TABLE, null, initialValues);
}
Run Code Online (Sandbox Code Playgroud)

(db是.的一个例子SQLiteDatabase.)

我尝试了这种方法insertOrThrow()而不是insert(),但它看起来和它一样insert().也就是说,如果该值已经在行中,则会再次插入该值,因此该行现在具有两个相同值的值.

java android sql-insert android-sqlite

15
推荐指数
2
解决办法
3万
查看次数

在棉花糖上打破分析?

我正在使用分析,在编译时我得到了这个程序警告:

Warning: com.google.android.gms.internal.zzw$zza: can't find superclass or interface org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning: com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.NameValuePair
Warning: com.google.android.gms.analytics.internal.zzam: can't find referenced class org.apache.http.client.utils.URLEncodedUtils
Run Code Online (Sandbox Code Playgroud)

以及更多.

我正在使用这些依赖项:

compile 'com.google.android.gms:play-services-base:7.8.0'
compile 'com.google.android.gms:play-services-gcm:7.8.0'
Run Code Online (Sandbox Code Playgroud)

这是一个错误吗?那有什么解决方法吗?

android google-analytics google-play-services android-6.0-marshmallow

10
推荐指数
3
解决办法
1764
查看次数

在不使用layout_weight的情况下,使两个LinearLayout占据屏幕的50%

我目前正在做横向屏幕的特殊xml布局,其中存在4个图像,2个LinearLayouts彼此相邻,每个图像有2个图像.这些LinearLayouts我打电话linearLayout1linearLayout2.

linearLayout1 标有蓝色矩形:

linearLayout1

linearLayout2 标有蓝色矩形:

linearLayout2

如您所见,第一个使用约80%的屏幕,而第二个使用剩下的.我当然不想要这个,我想要50%.我无法使用,layout_weight因为它已经在LinearLayouts本身使用(两个图像的定位),嵌套的权重对性能不利.

我尝试了很多不同的变体,但我无法让两个LinearLayouts分别拥有50%的屏幕.这是代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/db1_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<LinearLayout
    android:id="@+id/title_container"
    style="@style/TitleBar" >

    <ImageView
        style="@style/TitleBarLogo"
        android:contentDescription="@string/imgViewDesc"
        android:src="@drawable/title_logo" />

    <ImageView
        style="@style/TitleBarSeparator"
        android:contentDescription="@string/imgViewDesc" />

    <TextView style="@style/TitleBarText" />

    <ImageButton
        style="@style/TitleBarAction"
        android:contentDescription="@string/imgViewDesc"
        android:onClick="onClickAbout"
        android:src="@drawable/title_about" />
</LinearLayout>

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/title_container"
    android:layout_above="@+id/mobFoxView" >

    <!-- LEFT COLUMN -->

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/mobFoxView"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/linearLayout2"
        android:background="@color/white"
        android:gravity="center"
        android:orientation="vertical"
        android:weightSum="2" >

        <ImageView
            android:id="@+id/imgNews"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:contentDescription="@string/imgViewDesc"
            android:onClick="onClickFeature"
            android:src="@drawable/front_news_1" />

        <ImageView
            android:id="@+id/imgReleases"
            android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-linearlayout

7
推荐指数
2
解决办法
2万
查看次数

更改图库中的边框样式

我正在学习这个教程.正如您在图像上看到的那样,标准灰色边框将应用于图库中的所有元素.我想删除这个相当丑陋的边框,或者实际上,使它成为1 px边框(或者只是这样,图像可以相互区分).我尝试删除此行:

imgView.setBackgroundResource(GalItemBg);
Run Code Online (Sandbox Code Playgroud)

这删除了边框,但随后图像相互重叠,它仍然不是很漂亮.

那么,我该如何改变边界呢?如何让画廊元素彼此不重叠?

android border gallery

6
推荐指数
1
解决办法
8038
查看次数

SharedPreferences 重置:重置后地图大小不为 0

我正在尝试删除我的SharedPreferences,但它不起作用:size没有像我期望的那样设置为 0。

SharedPreferences sp = context.getSharedPreferences(name, mode);
SharedPreferences.Editor e = sp.edit();
e.clear();
e.commit();
Map<String, ?> map = sp.getAll();
int size = map.size();
Run Code Online (Sandbox Code Playgroud)

有什么建议?

private static String name = "ABC_PREFS";
private static int mode = Context.MODE_PRIVATE;
Run Code Online (Sandbox Code Playgroud)

android android-preferences

5
推荐指数
1
解决办法
377
查看次数

以编程方式添加到TableLayout的视图未显示

我正在尝试向TableLayout添加视图,但它们根本不会显示(我正在模拟器上测试).实际上我写了比这更多的代码,即将textviews添加到tablerows中,但我已经将其缩减到了这一点,即使这样也行不通.知道为什么吗?

这是代码test.xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
</TableRow>

<TableRow
    android:id="@+id/tableRow2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TEST" >
    </TextView>
</TableRow>

</TableLayout>
Run Code Online (Sandbox Code Playgroud)

和java代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.test);

    /* Find Tablelayout defined in test.xml */
    TableLayout tl = (TableLayout) findViewById(R.id.tableLayout);
    /* Create a new row to be added. */
    TableRow tr = new TableRow(this);
    tr.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));
    /* Create a Button to …
Run Code Online (Sandbox Code Playgroud)

android android-view android-tablelayout

4
推荐指数
1
解决办法
4639
查看次数

RGB图像到二进制图像

我想在MATLAB中加载RGB图像并将其转换为二进制图像,我可以在其中选择二进制图像具有多少像素.例如,我将300x300 png/jpg图像加载到MATLAB中,最终得到的二进制图像(像素只能是#000或#FFF)可能是10x10像素.

这是我到目前为止所尝试的:

load trees % from MATLAB
gray=rgb2gray(map); % 'map' is loaded from 'trees'. Convert to grayscale.
threshold=128;
lbw=double(gray>threshold);
BW=im2bw(X,lbw); % 'X' is loaded from 'trees'.
imshow(X,map), figure, imshow(BW)
Run Code Online (Sandbox Code Playgroud)

(我从互联网搜索中得到了一些上述内容.)

在做这个时,我最终得到了一个黑色的图像imshow(BW).

rgb matlab image image-processing

4
推荐指数
1
解决办法
3万
查看次数

引号未在显示屏上显示

在我的字符串xml文件中,我有一个这样的行:

<string name="infoHeader">random "text" here</string>
Run Code Online (Sandbox Code Playgroud)

但它只显示为

随机文字在这里

在手机的显示屏上,即没有引号.

我通过谷歌阅读了它,并尝试了一些HTML样式:

<string name="infoHeader">random &quot;text&quot; here</string>
Run Code Online (Sandbox Code Playgroud)

然后使用:

String hej = res.getString(R.string.infoHeader);     
Spanned marked_up = Html.fromHtml(hej);
((TextView)findViewById(R.id.infoHeader)).setText(marked_up, BufferType.SPANNABLE);
Run Code Online (Sandbox Code Playgroud)

但它仍然无效.我尝试了其他一些HTML,就像这样&lt;i>text&lt;/i>,效果很好.怎么了?

html xml android

3
推荐指数
1
解决办法
3624
查看次数