小编qui*_*tor的帖子

getWidth()和getHeight()始终返回0.自定义视图

在片段中,我使用多个子视图为一个布局充气.我需要获得其中一个的尺寸(宽度和高度),这是一个自定义视图.

在自定义视图类中,我可以轻松完成.但是如果我尝试从片段中做到这一点,我总是得到0作为维度.

 public void onViewCreated(View view, Bundle savedInstanceState) {

    super.onViewCreated(view, savedInstanceState);
    View culoide = view.findViewWithTag(DRAW_AREA_TAG);
    Log.d("event", "culoide is: "+culoide.getWidth()); // always 0
}
Run Code Online (Sandbox Code Playgroud)

我认为onViewCreated应该是获得它的正确位置,但这种情况发生了.我在super.onViewCreated之前尝试过,在调试它看起来像'findViewWithTag'找到了正确的视图,仅尝试使用api 7 v4支持.

有帮助吗?

android android-view

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

android无法启动模拟器:无法运行程序

我在Ubuntu上成功安装了android SDK和android eclipse插件.

在我删除Ubuntu并安装Linux Mint之前,每件事情都运行良好.我再次安装了SDK并使用了我在Ubuntu上使用的相同eclipse副本,但现在所有的android应用程序都包含错误,我无法启动模拟器.

启动模拟器时会出现此消息

Starting emulator for AVD 'test' Failed to start emulator: Cannot run program "/home/anas/android//tools/emulator": error=2, No such file or directory
Run Code Online (Sandbox Code Playgroud)

虽然android SDK安装在指定的路径中,并且文件(模拟器)存在于同一路径中.

我的所有应用程序都包含相同的错误 R can not be resolved to a variable

这里有什么问题?

eclipse linux ubuntu android

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

如何在android中实现片段内显示和隐藏片段

如何在Android中实现片段内显示和隐藏片段?我在活动中添加了两个片段.包含菜单和一个片段的一个片段包含子菜单.菜单片段中有很多按钮,如家,想法等.如果我点击想法按钮.我必须显示子菜单.如果我再次点击idea按钮,我必须隐藏子菜单.任何人都可以提供示例,或者如何访问另一个片段中的一个视图片段?

这是我的布局主要

?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<fragment class="com.gcm.fragment.CommonFragment"
            android:id="@+id/the_frag"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />  
 <fragment class="com.gcm.fragment.SubFragment"
            android:id="@+id/the_frag1"
            android:layout_marginTop="130dip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />             


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

在我的片段中

package com.gcm.fragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class CommonFragment extends Fragment implements OnClickListener {
    TextView txtIhaveIdea=null;
  boolean menuVisible=false;
    public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { 
        ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.collapsed_menu2, container, false); 

        txtIhaveIdea=(TextView)layout.findViewById(R.id.txtIhaveAnIdea);
        txtIhaveIdea.setOnClickListener(this);

        return …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-fragmentactivity

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

如何使用netcat发送文件,然后保持连接活动?

我发出命令:

netcat serveraddress myport < MY_FILE
Run Code Online (Sandbox Code Playgroud)

问题是,一旦发送文件,netcat就会发送一条消息来关闭连接.我需要在发送该文件后从控制台写入消息.我记得已经对pipileline做了一些事情到stdin ..是这样的吗?

netcat serveraddress myport < MY_FILE | 
Run Code Online (Sandbox Code Playgroud)

那现在不行.

我正在使用unix.

额外信息:这不承担服务器端的控制(EG使用服务器端的netcat来监听入站连接)

unix sockets netcat

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

android中片段的事务导致空白屏幕

如果它有帮助,我想要的东西与谷歌教程中的内容类似

但是在转换之前会创建一个片段.如果我这样做,过渡工作正常; 但我不能用这种方法

=====

针对API 7+,我只想在整个屏幕中看到一个片段,并使用一个按钮(一个带有onTouch事件的绘制按钮),然后交替使用第二个片段,反之亦然.

但是当我用第二个片段替换第一个片段时,或者如果我使用fragmentTransaction.show和fragmentTransaction.hide,我得到一个空白屏幕; 在我得到空白屏幕之前,我可以切换两次.我不想在后台上.

我在MainActivity的onCreate中创建片段:

DiceTable diceTable = new DiceTable();
Logger logger = new Logger();
fragmentTransaction.add(diceTable, DICETABLE_TAG);
fragmentTransaction.add(logger, LOGGER_TAG);
fragmentTransaction.add(R.id.fragment_container, logger);
fragmentTransaction.add(R.id.fragment_container, diceTable);
Run Code Online (Sandbox Code Playgroud)

然后在一个方法(从片段调用)我做切换:

    Logger logger = (Logger)fragmentManager.findFragmentByTag(LOGGER_TAG);
    DiceTable diceTable = (DiceTable)fragmentManager.findFragmentByTag(DICETABLE_TAG);

    if (diceTable.isVisible()) {
        fragmentTransaction.replace(R.id.fragment_container, logger);

        fragmentTransaction.commit();
        fragmentTransaction.hide(diceTable);
        fragmentTransaction.show(logger);
    }
    else if (logger.isVisible()) {
        fragmentTransaction.replace(R.id.fragment_container, diceTable);

        fragmentTransaction.commit();
        fragmentTransaction.hide(logger);
        fragmentTransaction.show(diceTable);
    }
Run Code Online (Sandbox Code Playgroud)

这不是我应该怎么做的?

更换碎片时出现空白屏幕

android android-layout android-fragments

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

Logcat的日志时间戳不按顺序排列

我正在调试数据连接,事情发生的顺序很重要.我在终端中使用带有ADB时间戳的logcat,并收集我稍后分析的小时日志.我遇到的问题是,时间戳有时不是顺序的.由于Logcat是一个循环缓冲区,我不明白为什么会这样.所以,如果时间戳中存在错误或者事件实际上没有按顺序记录,我就会徘徊,我应该参考日志序列而不是时间戳(请参阅第8和第9行转换).有人知道吗?用于获取日志的命令是:

adb logcat -b radio -v time

和日志:

...
09-06 18:32:29.426 D/GSM     (  200): getNitzTimeZone returning America/Detroit
09-06 18:32:29.434 I/AT      (   65): AT(14)< +CGDCONT: 1,"IP","pda.bell.ca","",0,0
09-06 18:32:29.434 I/AT      (   65): AT(14)< OK
09-06 18:32:29.434 E/RIL     (   65): processRequest: OPERATOR
09-06 18:32:29.434 E/AT      (   65): ---AT+COPS=3,0;+COPS?;+COPS=3,1;+COPS?;+COPS=3,2;+COPS?
09-06 18:32:29.434 I/AT      (   65): AT(14)> AT+COPS=3,0;+COPS?;+COPS=3,1;+COPS?;+COPS=3,2;+COPS?
09-06 18:32:29.434 D/RILJ    (  200): [UNSL]< UNSOL_DATA_CALL_LIST_CHANGED [DataCallState: { cid: 1, active: 0, type: IP, apn: pda.bell.ca, address:  }]
09-06 18:32:29.434 I/GSM     (  200): NITZ: Setting time of …
Run Code Online (Sandbox Code Playgroud)

android adb logcat

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

如何检测android中的密钥保护状态

我有一个应用程序需要在调用之前检测密钥保护的先前状态,disableKeyguard()reenableKeyguard()由用户设置!有没有办法完成这项任务?

android android-service

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

在屏幕方向更改时恢复对象

在我的代码中,我创建了一个卡类; 我稍后在gridview中展示了一堆卡片.在屏幕方向改变时,我正在丢失所有卡片; 在我之前的问题中,我指出了正确的方向.

现在,我在Android文档中找到的内容以及StackO中的内容就是这样

@Override
    protected void onSaveInstanceState(Bundle outState) {
    outState.putInt(...);
    super.onSaveInstanceState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    some_int_var = savedInstanceState.getInt(...);
super.onRestoreInstanceState(savedInstanceState);
Run Code Online (Sandbox Code Playgroud)

}

现在,我这样做好,因为Bundle对象有几个方法,如putString,Char等.原语加上字符串.但我的卡怎么样?它们是向量中的Card对象,因此我不能使用任何这些方法.

如何在不使用onRetainNonConfigurationInstance的情况下恢复该向量,也不会阻止活动重置?在Android文档中,如果要重新启动重型数据,建议执行此操作,但这不是我的情况.

android reset screen-orientation

2
推荐指数
1
解决办法
978
查看次数

Android区分点击和双击

我正在使用这种onTouch方法来触摸ACTION_UPGestureDetector捕捉双击,我的问题是双击结果点击然后双击,然后点击.有没有办法让双击阻止水龙头或类似的东西?我从逻辑上知道它的行为是正确的,所以如果你建议我找另一种方式来评论,请不要投票.谢谢!

android android-gesture

2
推荐指数
1
解决办法
1748
查看次数