小编Den*_*ter的帖子

理解Android XML layout_weight的问题

我真的试过,但我无法理解Android如何解释layout_weight设置......

我想要实现的是

  • 顶部有一个固定高度的标题
  • 底部的输入区域包含EditText和Button
  • 中间的一个内容部分,它占据了剩下的空间

键入时我想将EditText增长到特定高度,并在输入的文本超出可用高度时开始滚动.这样做我需要周围的环境LinearLayout与EditText一起成长.

如果我为内部定义一个特定的高度,LinearLayout它将不会增长.如果我不这样做,内部布局占用所有空间而不是ScrollView,无论我尝试使用什么layout_weight.:(

我当前的XML看起来像这样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="I'm a header" />
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="bottom">
        <LinearLayout
            android:id="@+id/itemContainer"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </ScrollView>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:padding="2dp"
        android:gravity="bottom"
        android:isScrollContainer="true"
        android:background="@drawable/steel" >
        <EditText
            android:id="@+id/edittext01"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:scrollbars="vertical"
            android:fadingEdge="vertical"
            android:fadingEdgeLength="60dp"
            android:maxHeight="40dp"
            android:textSize="15sp" />
        <Button
            android:id="@+id/button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.8"
            android:layout_gravity="right"
            android:text="Send"
            android:textStyle="bold"
            android:textSize="15sp" />
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

任何提示都非常感谢!

xml android android-linearlayout

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

如何为原生Android浏览器开发插件

我在网上搜索但没有运气:如何开发原生Android浏览器的插件?!Google和Android SDK均未提供有关此主题的信息.

browser plugins android

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

如何从Android上保存的帐户中检索Facebook-AuthToken

我正在尝试使用以下代码检索Facebook的AuthToken(由Facebook for Android保存).

AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccountsByType("com.facebook.auth.login");
if (accounts.length > 0) {          
    for(int j = 0; j < accounts.length; j++) {
        Account account = accounts[j];
        if(account.type != null && account.type.equals("com.facebook.auth.login")) { 
            Log.e(RuntimeVars.MY_NAME, "FACEBOOK-TYPE FOUND");
            am.getAuthToken(account, "com.facebook.auth.login", null, ConversationList.this,
                new AccountManagerCallback<Bundle>() {
                    public void run(AccountManagerFuture<Bundle> arg0) {
                        try {
                            Bundle b = arg0.getResult();
                            Log.e(RuntimeVars.MY_NAME, "THIS AUTHTOKEN: " + b.getString(AccountManager.KEY_AUTHTOKEN));
                        }
                        catch (Exception e) {
                            Log.e(RuntimeVars.MY_NAME, "EXCEPTION@AUTHTOKEN");
                        }
                    }
                }, null);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

找到登录凭据并将FACEBOOK-TYPE …

android facebook auth-token accountmanager

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

docker-compose无法连接外网

我创建了一个外部覆盖网络:

docker network create --driver overlay --subnet=10.0.9.0/24 mynetwork
Run Code Online (Sandbox Code Playgroud)

网络创建成功:

$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
37295f249f91        bridge              bridge              local               
c2ec03c99888        docker_gwbridge     bridge              local               
33dd13c9686d        host                host                local               
27goixjy0jys        ingress             overlay             swarm               
75508732fab2        none                null                local               
ef6fti3kq6w4        mynetwork           overlay             swarm  
Run Code Online (Sandbox Code Playgroud)

当我尝试将容器放入 my 中时docker-compose.yml,服务的创建失败并显示

$ docker-compose up
Creating service-lb

ERROR: for service-lb  network mynetwork not found
ERROR: Encountered errors while bringing up the project.
Run Code Online (Sandbox Code Playgroud)

我的docker-compose.yml看起来像这样:

version: "2"
services:
    service-lb:
        image: myreg:5000/myorg/service-lb:latest
        ports:
        - "0.0.0.0:10080:80"
        dns_search: …
Run Code Online (Sandbox Code Playgroud)

docker docker-compose docker-network

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

我的静态方法的每秒HttpsUrlConnection请求都在Android上失败

我的静态HTTPS连接方法存在很大问题.每秒请求失败HttpsUrlConnection.getResponseCode()返回-1.所以每次调用都很有效,按预期返回数据.

这是我在我的应用程序的不同角落使用的静态类的方法.我猜想当方法第一次返回时,有什么东西我没有正确清理,并且通过第二次调用方法可能会导致问题被破坏.但我很难找到任何线索.

我目前正在使用此类与无效SSL证书的主机通信.不会在应用程序的最终版本中使用它,但是现在我需要省钱.;)

public static String makeInvalidHTTPSRequest(String url, String[] postVars, String userName, String userPass, Context ctx) throws MalformedURLException, IOException, NoSuchAlgorithmException, KeyManagementException {
    StringBuffer sb = new StringBuffer();
    String serverAuth = null;
    String serverAuthBase64 = null;
    StringBuffer urlParameters = new StringBuffer();
    InputStream rcvdInputStream = null;

    if (checkNetworkAvailability(ctx) == false) {
        GeneralMethods.writeLog("Network unavailable", 1, GeneralMethods.class);
        return null;
    }

    SSLContext sc = null;
    sc = SSLContext.getInstance("TLS");
    sc.init(null, new TrustManager[] { new KTPTrustManager() }, new SecureRandom());

    GeneralMethods.writeLog("makeInvalidHTTPSRequest-> " …
Run Code Online (Sandbox Code Playgroud)

android static-methods httpurlconnection

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

如何找出网络服务器显示的默认页面的名称?

我在Java应用程序中通过I/O-streaming下载各种文件.只要我有一个包含文件名的完整URL路径,接收和保存这些文件就可以正常工作,但是如何找到域的索引文件的名称(如Apache中所定义的DirectoryIndex)?HTTP标头不提供此信息,也不提供该URLConnection方法.

非常感谢!

好吧
S.

java urlconnection http-headers directoryindex

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

如何很好地缩放TextView for Android的背景图像

我正在为我的Android应用扩展TextView.我想创建"气泡"来在对话中显示短信,类似于原生的iPhone短信对话.

有没有办法实现背景图像的大小调整而不只是拉伸它?我希望有一个背景图像可以保持它的角落,但只能在定义的区域内拉伸.我认为这应该是可能的,因为我已经在短信应用程序中看到了它,但我想知道如何实现它.

android textview

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

从Android上的适配器中刷新ExpandableListView

我在如何刷新ExpandableListView其中一个childViews时遇到了麻烦.

listView包含一个文件列表,我想提供删除这些文件的可能性.但是在执行删除后,ExpandableListView需要刷新.我实现了自己的适配器,扩展了BaseExpandableListAdapter.似乎没有办法从覆盖getChildView()方法中获取我的父对象来发送notifyDataSetChanged().:-s

我想过向我的活动发送一个意图,其中包含有关组状态(折叠/扩展)的信息以及在接收时刷新,但即便如此,我也需要该ExpandableListView对象.

如何才能做到这一点?

提前致谢!

好吧
S.

android refresh expandablelistview

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