小编Cra*_*ner的帖子

ImageView中的填充不起作用

我想制作一个包含顶栏和图像的屏幕.我使用TextView作为顶部栏,使用ImageView作为图像.我想仅将填充设置为图像视图.我的xml如下.填充操作无效.任何人都可以解释为什么和做什么?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"   
    android:background="@drawable/background" >

    <TextView android:id="@+id/topBar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="@string/home"
        android:textSize="20sp"
        android:textColor="#ffffff"
        android:textStyle="bold"
        android:shadowColor="#000000"
        android:shadowRadius="1"
        android:shadowDy="-1" 
        android:gravity="center"
        android:background="@drawable/navBar"/>

    <ImageView android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"   
        android:paddingLeft="10dp"
        android:paddingTop="10dp"
        android:paddingRight="10dp"
        android:paddingBottom="10dp"
        android:layout_below="@+id/topBar"        
        android:background="@drawable/image"/>

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

android padding imageview android-layout

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

如何在Android ListView中添加子项?

我已经使用以下布局和ListActivity类从Vogella.com获取了android listView的帮助.

RowLayout.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="wrap_content" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="22px"
        android:layout_height="22px"
        android:layout_marginLeft="4px"
        android:layout_marginRight="10px"
        android:layout_marginTop="4px"
        android:src="@drawable/icon" >
    </ImageView>

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label"
        android:textSize="20px" >
    </TextView>

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

MyListActivity.java

package de.vogella.android.listactivity;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MyListActivity extends ListActivity {
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
        "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
        "Linux", "OS/2" };
    // use …
Run Code Online (Sandbox Code Playgroud)

android listview

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

如何从服务检查活动是否在后台/前台运行?

我创建了一个服务,它从一个活动的onCreate开始,并停止在activity的onDestroy方法上.现在我必须从服务的方法中检查活动是否在前台/后台运行(对于某些情况,例如应用程序被强制关闭).我怎样才能做到这一点?

  1. 我需要这样做,因为我知道如果任何应用程序被强制关闭或任何类型的崩溃,无法保证调用活动的onDestroy方法.因此,我的活动启动时启动的服务不会在任何崩溃或任何强制关闭事件后停止.

  2. 我已经看到了可以检查前台活动的链接.但我需要在任何状态(前景或后台)检查正在运行的活动

service android android-activity

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

如何在android中使用相机检查图像是在纵向模式还是横向模式下捕获的?

我正在创建一个打开照片库的应用程序,通过从图库中选择该照片,照片将显示在另一个活动中。我的问题是,我以纵向模式拍摄的照片在显示后会旋转。但我在横向模式下拍摄的照片将正确显示。

这就是为什么,我必须使用 Android 中的相机检查图像是在纵向模式还是横向模式下拍摄的,以便我可以旋转纵向拍摄的照片。谁能帮我怎么做?

注意:纵向拍摄的图像和横向拍摄的图像的宽度和高度相同。

android orientation photo-gallery

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

对话框中的imageView的setOnClickListener不起作用

我在按钮单击时使用了以下方法来显示带有图像列表的对话框.如果我从图像中删除setOnclickListener,该对话框正常工作.但是如果我将setOnclickListener用于图像,应用程序将会停止运行.

 private void showFrame(){
            frameDialog = new Dialog(CameraActivity.this);
            frameDialog.setContentView(R.layout.frame_selection);
            frameDialog.setTitle("Select a frame");

            ImageView thumb1 = (ImageView) findViewById(R.id.thumbView1);
            ImageView thumb2 = (ImageView) findViewById(R.id.thumbView2);
            ImageView thumb3 = (ImageView) findViewById(R.id.thumbView3);

            frameDialog.show();
            thumb1.setOnClickListener(
                     new View.OnClickListener() {
                         @Override
                         public void onClick(View v) {
                                Toast.makeText(getApplicationContext(), "to this is okay!", Toast.LENGTH_LONG).show();
                                frameDialog.dismiss();

                         }
                     }
                 );
thumb2.setOnClickListener(
                     new View.OnClickListener() {
                         @Override
                         public void onClick(View v) {
                                Toast.makeText(getApplicationContext(), "to this is okay!", Toast.LENGTH_LONG).show();
                                frameDialog.dismiss();

                         }
                     }
                 );
                thumb3.setOnClickListener(
                     new View.OnClickListener() {
                         @Override
                         public void onClick(View …
Run Code Online (Sandbox Code Playgroud)

android nullpointerexception imageview onclicklistener

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