GVKun编程网logo

Android Studio preview 不固定及常见问题的解决办法(android studio preview 窗口怎么设置)

9

这篇文章主要围绕AndroidStudiopreview不固定及常见问题的解决办法和androidstudiopreview窗口怎么设置展开,旨在为您提供一份详细的参考资料。我们将全面介绍Androi

这篇文章主要围绕Android Studio preview 不固定及常见问题的解决办法android studio preview 窗口怎么设置展开,旨在为您提供一份详细的参考资料。我们将全面介绍Android Studio preview 不固定及常见问题的解决办法的优缺点,解答android studio preview 窗口怎么设置的相关问题,同时也会为您带来Android ScrollView嵌套ExpandableListView显示不正常的问题的解决办法、Android Studio 1.1 Preview 1 预览版发布、Android Studio 1.1 Preview 2 预览版发布、Android Studio 1.2 Preview 1 发布的实用方法。

本文目录一览:

Android Studio preview 不固定及常见问题的解决办法(android studio preview 窗口怎么设置)

Android Studio preview 不固定及常见问题的解决办法(android studio preview 窗口怎么设置)

Android Studio提供了一个强大的“Preview”工具,可以帮助您预览您的布局文件将如何在用户的设备上呈现。XML布局可能是Android开发中最常用的资源。 您的项目中每个活动至少有一个布局文件。 Android Studio的预览工具可帮助您实现这些伟大的设计,并快速迭代它们,甚至不需要运行您的应用程序。它还允许您查看布局的不同配置,例如在纵向或横向时的外观,或者TextView在多个语言环境(如英语,德语或希腊语)上的外观。

即使预览工具是强大的,可以使你的发展日子轻而易举,与此同时,它也有一些缺点会让程序猿抓狂。这篇文章谈论Preview的常见问题和技巧。

前阵子用 AndroidStudio,不知道点错了什么按钮,preview 视图窗口不是固定在一侧。只要点击 xml 界面,就隐藏了 preview 窗口,根本开发不了。找来找去,发现设置处没有docked mode属性。

没有 docked mode 属性

网上找了很多资料,才解决了。办法如下:

  1. 点击preview,显示视图窗口;
  2. 点击菜单栏的window;
  3. 选中Active Tool Window;
  4. 选中Docked Mode;

操作

这里是最常见的关于Preview的问题列表和解决方案(图片请右键用新标签放大查看):

问题1:Preview看起来为空

假设你有一个布局,其内容将从后端获得的数据填充…你很快意识到,由于内容是动态的,预览工具不能填充屏幕,你什么也看不到。对这个问题的一个较为简单解决方案是在真机上测试,那时你有这些数据,但是这样Preview的意义就失去了。

在这种情况下的问题是TextView和ImageView没有任何内容可供显示。 这是处理动态内容时的常见问题。即使代码编译没有问题,没有人可以在不查看XML代码的情况下理解该布局。

当创建使用任何后端数据相关视图的布局时,一个好的做法是仅在预览时填充它。通过使用tools命名空间而不是android来声明xml属性,这将允许您指定只在预览时使用的属性。例如我们使用tools:text =“Title”和tools:src =“@ drawable / cool_pic”,大功告成!

 

使用tools前缀声明的属性完全与android一样,但仅用于预览。使用tools:text 而不是Android:text,保证了你所有的内容都只是在预览的时候会出现,程序运行起来不会出现所有tools相关的东西。

如果你没有足够的符合所有ImageView要求的宽高比的图片(jpg等),会发生什么? 您可以让设计狮提供一些资源来测试各种适配,不过这可能需要一些额外的努力和维护;这时也可以使用tools:rcs或者tools:layout_height和tools:layout_width来测试显示效果,而不必修改真实属性。

问题2:测试最大宽高

或者当您的布局旨在显示来自外部源的一些内容时,它有时被要求具有一些最大宽度或/和高度(也就是使用了maxHeight属性),来确保您的布局看起来美观,即使外部源发送大于预期或某些宽高比未被同意的图像。这时可以使用tools:layout_height和tools:layout_width,并且设置一个固定颜色的toos:background来预览各个尺寸下的图片可以在ImageView中占用的空间。

问题3:修复损坏的预览

如下图所示的错误经常发生:创建自定义view时,务必确保您的视图可以实例化,而不使用任何在预览期间可能不存在的外部依赖项。请记住,预览不会在应用程序中运行,而是在IDE中的JVM上运行。 这将模拟在Android设备上的工作原理,你应该假设你不能访问任何数量的不在View框架内的依赖。使用例如Glide的图像加载器将是不可能的。 出于同样的原因,任何依赖注入框架将不工作,因为它不会在预览上下文中初始化,导致视图在被扩充时抛出异常。

在这种情况下可以使用View.isInEditMode()。 使用它来检查您是否是正在预览,并跳过在Preview时不可用的依赖:

public ImageWithCaptionView(Context context,AttributeSet attrs) {
  super(context,attrs);
  if (!isInEditMode()) {
   ArticlesApplication.getInjector().inject(this);
  }
}

问题4:merge布局重叠

merge标签可以帮助您减少布局代码的重复。

然而,merge的问题是,它内部的所有组件将被折叠在一起,同时显示在预览里,造成视觉混乱。如下图所示,TextView覆盖在ImageView的上面:

您可以使用工具:tools:showIn=”layout”来显示使用它的一些其他现有布局内的布局的内容。 请注意,如果您在多个地方使用不同的父布局,则只能选择一个布局进行预览。

从Android Studio 2.2开始,您现在可以使用工具:parentTag =“LinearLayout”例如将渲染布局为LinearLayout。下图是使用后的效果,不再有重叠:

问题5:在预览时显示隐藏的视图

你的活动可能包含一些在onCreat时需要隐藏的View,但在一些事件后显示它们。通过设置这些视图在布局中的visibility:”GONE”,可以确保它们永远不会在预览时可见。

问题是,这些视图将从预览中消失,如果一些其他开发人员打开布局,并在预览中查找它们,他们将无法找到它。这是一个问题,因为它需要更多的精力和时间来了解屏幕上发生了什么。

您可以使用tools:visibility =“visible”属性,以仅在预览面板中显示它。

问题6:ListView的Item和Header/Footer预览

使用tools:listitem / tools:listheader / tools:listfooter可以实现在预览中增加item、header、footer的效果。例如:

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@android:id/list"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:listitem="@layout/sample_list_item"
 tools:listheader="@layout/sample_list_header"
 tools:listitem="@layout/sample_list_footer" />

此特性在AS2.2有bug(无效),并在2.3中修复。

本文大部分翻译自https://www.novoda.com/blog/layout-preview-101/,针对实际情况做出了少量修改,补充了问题6。

Android ScrollView嵌套ExpandableListView显示不正常的问题的解决办法

Android ScrollView嵌套ExpandableListView显示不正常的问题的解决办法

Android ScrollView嵌套ExpandableListView显示不正常的问题的解决办法

前言:

   关于ScrollView嵌套ExpandableListView导致ExpandableListView显示不正常的问题解决方法有很多,在这里介绍一种小编亲自测试通过的方法。

重写ExpandableListView:

实例代码:

package com.jph.view; 
 
import android.content.Context; 
import android.util.AttributeSet; 
import android.widget.ExpandableListView; 
 
/** 
 * 重写ExpandableListView以解决ScrollView嵌套ExpandableListView 
 *<br> 导致ExpandableListView显示不正常的问题 
 * @author jph 
 * Date:2014.10.21 
 */ 
public class CustomExpandableListView extends ExpandableListView { 
 
  public CustomExpandableListView(Context context) { 
    super(context); 
    // Todo Auto-generated constructor stub 
  } 
 
  public CustomExpandableListView(Context context,AttributeSet attrs) { 
    super(context,attrs); 
    // Todo Auto-generated constructor stub 
  } 
 
  public CustomExpandableListView(Context context,AttributeSet attrs,int defStyle) { 
    super(context,attrs,defStyle); 
    // Todo Auto-generated constructor stub 
  } 
   @Override  
  protected void onMeasure(int widthMeasureSpec,int heightMeasureSpec) {  
    // Todo Auto-generated method stub  
    int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);   
    super.onMeasure(widthMeasureSpec,expandSpec);  
  }  
} 

在XML中将ExpandableListView替换为重写的ExpandableListView即可。

<com.jph.view.CustomExpandableListView android:id="@+id/elItems" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

Android Studio 1.1 Preview 1 预览版发布

Android Studio 1.1 Preview 1 预览版发布

Android Studio 1.1 Preview 1 预览版发布,该版本主要是 bug 修复,目前团队同时也在进行 1.2 版本的开发,1.2 版本主要是基于 IntelliJ 14 的代码基础。

该版本包含如下改进:

  • New projects now create launcher icons as @mipmap resources instead of @drawable (see http://android-developers.blogspot.com/2014/10/getting-your-apps-ready-for-nexus-6-and.html for more)

  • The various "cleanup" detectors for lint (e.g. checking that FragmentTransactions are committed, and that TypedArrays are recycled, and so on), now run incrementally within the IDE. They''ve also been extended to search for additional problems, such as missing close calls on database cursors, or missing release calls on SurfaceTextures:


  • There are a couple of new lint checks:

    • A lint check which tries to identify string resources that should probably be using plurals instead

    • A lint check which warns you that @android:string/yes returns OK, not Yes

    • Several other lint checks that were bytecode based and only ran from Gradle (not lint in the IDE) have been ported to run incrementally in the IDE: Uses of SimpleDateFormat which should probably use getDateInstance instead, checks that addJavaScriptInterface points to a class annotated with @JavaScriptInterface, and a check looking for leaked Handler objects.

  • There is a new template for creating watch faces for Android Wear:

同时修复了如下 bug:

82378: Android Studio doesn''t start, unable to find valid JVM

92858: Restrict IconDensities check with splits density data

81597: Incorrect inspection about Android problem for non-Android project

80668: Lint report doesn''t explain how to suppress warnings from Gradle.

80679: tools:background should not trigger an overdraw warning

92789: False positive in lint PropertyEscape

82588: Lint: Make TypographyQuotes work with plurals

82861: Library project is created with launcher icon resources

82862: The xxhdpi launcher icon differs from other densities

82351: src, layout folders are empty while creating new project

78625: AVD Default orientation

80940: Update lint to ECJ 4.4, ASM 5.0.3: NullPointerException by running lint

80872: Don''t match resource names for format-parameter only strings

82634: "Palette" show twice in View > Tools Window

94499: Fixing the device preview in the search and create cases

82564: Making AVD Manager separate (non-modal) window.

77158: Allow settings.gradle to include projects dynamically

76923: can''t create outgoing link from widgets that are in included layouts

81908: Check if mksdcard can be executed

82837: Update wizards to use new headers

82764: AVD Manager: SD Card Radio Button Selection

82991: AVD Manager: Fix Key lines of the Verify Configuration Screen

82106: install, bad link to linux KVM

77889: save screenshot: respect device art masks

81525: Added "Download JDK 7" quick-fix.

82813: uncommitted fragment transactions not highlighted by lint

81396: @DrawableRes doesn''t match R.mipmap drawables

79629: Translations Editor does not show newly added locale

82768: Making the AVD ID field look non-editable

93158: Properly handle parent class lookup in the API check for this-expressions

78382: Lint uses incorrect API level while analyzing Java Library modules

91988: FlagManager asserts on region code es-419

74568: ADV Manager has start button but no stop button!

80494: Move Clear All and Scroll to End actions

82203: Installer now waits for uninstaller

82126: studio.exe can again run on Win64

83198: NPE when missing dependency during import

82770: Updating api distributions and distribution dialog text

82812: Updating title of AVD Manager window

78668: Adding hardware buttons for nexus one and nexus s

82184:  file paths (in local.properties) are no longer treated as relative if they belong to a different platform.

82837: Use black icons only

81166: device chooser: Prefer to use a device rather than the emulator

82852: After switching device types, the system image list broke

82753: Use $ as separator inner classes in fragment names

77635: Fix scaling of device diagram.

82503: Adding defaults for new avd creation wizard

81739: Fixing avd duplication

79105: Fixing button styles in avd manager

81768: Compute default parameter values quickly

81662: Fixing skin chooser on windows

82282: Do not require approval of all licenses

81342: Improve JDK detection algorithm

77953: NPE on configuring library documentation

82159: Closing exported device files.

81713: Try to detect jdk location automatically on entering the step

81346: Visual feedback for ''Detect JDK'' button processing

81620: Do not download samples

79778: apk installation: do not throw error for unexpected dumpsys output

81499: device chooser: special case Google APIs target

+ Misc other fixes for crashes reported via the crash reporter

+ Bug fixes not tagged with a bug number in the commit message.

Android Studio 1.1 Preview 2 预览版发布

Android Studio 1.1 Preview 2 预览版发布

Android Studio 1.1 Preview 2 发布,跟 Preview 1 一样,该版本主要是 bug 修复,目前团队同时也在进行 1.2 版本的开发,1.2 版本主要是基于 IntelliJ 14 的代码基础。

In this build, there are several new lint checks:

  • Check for suspicious language/region combinations (where you are defining a translation for a language and specific locale, where the combination of language and region is unusual and it''s possible that you''ve used the wrong code.)

  • Checks that the tag passed to a Log.severity(tag, ...) call and its surrounding Log.isLoggable(tag) calls refer to the same tag. Similarly, it also checks that the logging level passed in to isLoggable matches the type of logging call, e.g. if if you check isLoggable(..., Log.DEBUG) you should log with Log.d, not Log.v or Log.i. 

  • Checks that the tag passed to the logging calls, if its value can be resolved, is at most 23 characters long (as required by the Logging API.)

  • Checks that calls to info, verbose and debug logging calls are surrounded by a conditional (e.g. isLoggable or BuildInfo.DEBUG) but only if that logging call "performs work" (e.g. concatenates non constant strings or performs methods calls etc). This check is off by default.

  • Check for using drawables instead of mipmaps for the launcher icon, where the application is also filtering the set of densities packaged into the APK. There is also a quickfix in the IDE for migrating an icon from a @drawable to a @mipmap.

此外,默认的启动图标已经更新到 Material Design 外观。同时包括一个 xxxhdpi density icon。

此版本修复的 bug:

56986: Incorrect flag for portuguese

59042: strings.xml reformated every time I create new Activity

77158: Sync removes modules that do not have a Gradle counterpart.

81457: Fixes low resolution icon in Linux.

82387: Add intention to correct XML namespace for support lib

82564: Making AVD Manager separate (non-modal) window.

92005: Allow cancelling task that retrieves device screenshots

93284: Including comments when merging xml

94499: Fixing the device preview in the search and create cases

97006: Gradle lint does not recognize Context.getDrawable() as API 21+

98297: Fix run dialog modality to allow avd manager interaction

98317: Fixing resource merge to work within new project wizard

98997: Pick test runner from Gradle while creating test configuration

101279: Fix id reference check to properly handle undefined id''s

103257: Append .exe extension on Windows (mksdcard)

103257: Welcome Wizard, on Windows, shows "Tools directory not found" error incorrectly

+ Bug fixes not tagged with a bug number in the commit message.

更多内容请看发行说明。


Android Studio 1.2 Preview 1 发布

Android Studio 1.2 Preview 1 发布

Android Studio 1.2 Preview 1 发布,此版本现已推送到 canary 频道,请注意,这只是个 Alpha 版本,建议继续使用 Android Studio 1.1 版本,或者两个都使用。

Android Studio 1.2 包括大量的新特性,是第一个基于 IntelliJ 14 的版本,包括 IntelliJ 14 的所有新特性和改进,比如新的调试器。

IntelliJ 14 新特性概览:https://www.jetbrains.com/idea/whatsnew/。

最新的 canary build 不仅仅是基于 IntelliJ 14,还基于 IntelliJ 14.1,现在正在开发中的版本。IntelliJ 14.1 值得关注的特性请看 here (scroll to "Notable changes in IntelliJ IDEA 14.1")。

Android Studio 1.2 Preview 1 现已提供下载:https://sites.google.com/a/android.com/tools/download/studio/canary/1-2-preview-1。

更多更新内容请看发行说明。

关于Android Studio preview 不固定及常见问题的解决办法android studio preview 窗口怎么设置的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Android ScrollView嵌套ExpandableListView显示不正常的问题的解决办法、Android Studio 1.1 Preview 1 预览版发布、Android Studio 1.1 Preview 2 预览版发布、Android Studio 1.2 Preview 1 发布的相关知识,请在本站寻找。

本文标签: