首页 \ 问答 \ Android Studio布局错误(Android Studio Layout Errors)

Android Studio布局错误(Android Studio Layout Errors)

嘿,我真的需要你的帮助。

我的问题是Android Studio不会在模拟器或物理设备中正确显示布局。 每当我放置一个textView,按钮等,我想将它居中(水平,垂直或两者),然后我启动模拟器它就会粘在左上角。

这是我的代码::

private void firstStage(){
    ViewGroup container = (ViewGroup) findViewById(R.id.container);
    container.removeAllViews();
    container.addView(getLayoutInflater().inflate(R.layout.first_stage, null));
}


private void showHint(){
    ViewGroup container = (ViewGroup) findViewById(R.id.container);
    container.removeAllViews();
    container.addView(getLayoutInflater().inflate(R.layout.first_hint, null));
    firstImage = (ImageView) findViewById(R.id.hintImage);
    firstImage.setImageResource(R.drawable.firsthint);
    Button back = (Button) findViewById(R.id.first_hint_backButton);
    back.setOnClickListener(this);


}

在showHint方法中一切正常..按钮和imageview是我设置它们的地方。

在firstStage方法中,我有一个textView,如果我选择带有“center”的东西,它总是在左上角,就像Android Studio突然无法处理重力:中心了。

我尝试创建一个新项目,但错误仍然发生。 如果我将textView设置为右侧,然后将其放在右边的中间,则可以正常工作。 但这不是一个长期的解决方案。 你有没有人遇到过同样的问题?

在你问之前,是的,我用“中心”尝试了一切。 在XML文件中,在代码中等等。

也许这也会对你有所帮助::

如果我通过setContentView(R.layout.first_stage)调用布局; 有用。 textView就在那里我想要它...我只是不知道为什么它不再适用于ViewGroup,当它完全适用于我的其他2个布局?!

这是我的布局代码::

<?xml version="1.0" encoding="utf-8"?>

RelativeLayout xmlns:android =“http://schemas.android.com/apk/res/android”android:layout_width =“match_parent”android:layout_height =“match_parent”

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="@string/first_stage"
    android:id="@+id/textView2"
    android:enabled="true"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

/ RelativeLayout的

编辑::

它现在有效!! 我将容器从RelativeLayout更改为FrameLayout。 我不知道为什么它现在有效,但它的确有效!

感谢pdegand59的快速帮助,真的很感激。


Hey I really need your help.

My problem is that Android Studio will not display the Layout correctly in the emulator or physical device. Whenever i place a textView, button etc. and i want to center it (horizontally, vertically or both), and i start the emulator it's stuck to the top left corner.

This is my code::

private void firstStage(){
    ViewGroup container = (ViewGroup) findViewById(R.id.container);
    container.removeAllViews();
    container.addView(getLayoutInflater().inflate(R.layout.first_stage, null));
}


private void showHint(){
    ViewGroup container = (ViewGroup) findViewById(R.id.container);
    container.removeAllViews();
    container.addView(getLayoutInflater().inflate(R.layout.first_hint, null));
    firstImage = (ImageView) findViewById(R.id.hintImage);
    firstImage.setImageResource(R.drawable.firsthint);
    Button back = (Button) findViewById(R.id.first_hint_backButton);
    back.setOnClickListener(this);


}

In the showHint Method everything works fine.. the button and imageview are there where i have set them.

In the firstStage method however i have a textView and it is always in the top left corner if I choose something with "center", like Android Studio suddenly can't handle gravity:center anymore.

I tried it with creating a new project but the error still occurs. If i set the textView to the right side and then put it in the middle with margin-right, it works. But that is not really a long-term solution. Did anyone of you experience the same problem?

And before you ask, Yes i have tried everything with "center". In the XML- file, in the code and so on.

Maybe this will also help you::

If i call the layout via setContentView(R.layout.first_stage); it works. The textView is right in there where i want it to be.. I just don't know why it won't work with ViewGroup anymore, when it works perfectly for my other 2 Layouts?!

This is my Layout-Code::

<?xml version="1.0" encoding="utf-8"?>

RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="@string/first_stage"
    android:id="@+id/textView2"
    android:enabled="true"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

/RelativeLayout

EDIT::

It works now!! I changed the container from being a RelativeLayout to a FrameLayout. I don't know exactely why it works now, but it works!!!

Thanks to pdegand59 for the fast help, really appreciate it.


原文:https://stackoverflow.com/questions/31650687
更新时间:2022-05-24 21:05

最满意答案

这是提到这个的文档 。 实际上,它并不明显,但它存在:

index.recovery.initial_shards

使用本地网关时,只有在群集中可以分配仲裁分片时才会恢复特定分片。 它可以设置为:

仲裁(默认)

法定人数-1(或一半)

充分

全1。

还支持数值,例如1。

如果您确实希望节点运行,请在index.recovery.initial_shards: 1文件中设置index.recovery.initial_shards: 1


Here's the documentation mentioning this. Indeed, it's not evident, but it's there:

index.recovery.initial_shards

When using local gateway a particular shard is recovered only if there can be allocated quorum shards in the cluster. It can be set to:

quorum (default)

quorum-1 (or half)

full

full-1.

Number values are also supported, e.g. 1.

If you really want to have your node running, set index.recovery.initial_shards: 1 in elasticsearch.yml file.

相关问答

更多
  • 你不能做你想要做的事情。 如果群集是红色的,则表示它不可访问,如果无法访问,则不会对分片或片段进行搜索,因此不会从分片返回结果。 结论,部分或无结果。 因此,除非在每个查询上检查群集运行状况,然后在返回运行状况检查GREEN之后再次查询结果,否则不能强制不获取部分结果。 显然这个解决方案有一个竞争条件,就像你在评论中提到的那样,但就目前而言,没有别的办法。 I couldn't find direct way to fail searches, when shards are missing, but El ...
  • 所有答案都是肯定的:) 节点通过传输端口相互通信,默认为9300端口(或第一个在(9300-9400)范围内的空闲端口。它们使用自定义二进制协议进行通信,基于对象的序列化(不是标准的java序列化)大多数情况虽然)。 群集中的任何节点都是群集感知的,并且知道分片的位置等等,因为它们都共享所谓的群集状态。 您可以向任何节点发送请求(读取和写入),并将其重新路由到有趣的节点,并根据请求的类型正确执行。 All the answers are yes :) The nodes communicate with e ...
  • 我会尝试解释一个真正的例子,因为答案和答复你似乎没有帮助你。 当您下载弹性搜索并启动它时,您将创建一个弹性搜索节点,该节点尝试加入现有的集群(如果可用)或创建一个新的集群。 假设您使用单个节点创建了自己的新集群,即刚启动的节点。 我们没有数据,因此我们需要创建一个索引。 创建索引时(索引第一个文档时也会自动创建一个索引),您可以定义多少个分片。 如果不指定一个数字,它将具有默认的分片数量:5个基数。 这是什么意思? 这意味着弹性搜索将创建5个主碎片,其中包含您的数据: ____ ____ __ ...
  • 可以使用弹性IP。 此外,由于您提到它是单节点群集 - 您可以使用localhost或私有IP。 如果使用弹性IP,则UI将始终位于同一公共IP上。 但是,如果您使用私有IP或localhost并且不将您的实例与弹性IP关联,则每次启动实例时都必须查找公共IP,然后使用IP连接到Web UI。 Elastic IP can be used. Also, since you mentioned it being a single node cluster - you can use localhost or ...
  • 在进行完全集群重新启动时,您需要至少启动数据节点的法定数量。 这是通过index.recovery.initial_shards配置的,它可以防止分配过时的分片副本。 index.recovery.initial_shards 仅当有足够的节点可用于分配足够的副本以形成仲裁时,才会恢复主分片。 它可以设置为: 仲裁(默认) 法定人数-1(或一半) 充分 全1。 还支持数值,例如1。 您可以在此处阅读官方文档中有关此配置的更多信息 你可以在这个elasticsearch github评论中找到类似的问题 Wh ...
  • 这是提到这个的文档 。 实际上,它并不明显,但它存在: index.recovery.initial_shards 使用本地网关时,只有在群集中可以分配仲裁分片时才会恢复特定分片。 它可以设置为: 仲裁(默认) 法定人数-1(或一半) 充分 全1。 还支持数值,例如1。 如果您确实希望节点运行,请在index.recovery.initial_shards: 1文件中设置index.recovery.initial_shards: 1 。 Here's the documentation mentionin ...
  • 如果您不关心重新启动期间的索引可用性,则可以重新启动节点B.如果您确实关心可用性,则可以: 要求ES通过分片分配过滤将分片从节点B移动到节点A. 创建一个副本 ,它将从节点B到节点A的分片进行复制 If you don't care about index availability during the restart period, you can restart node B. If you do care about availability, you can either: Ask ES to mo ...
  • 我有同样的问题,直到我读到重启容器化的consul节点时存在ARP表缓存问题。 据我所知,有2种解决方法: 使用--net = host运行容器 在重新启动容器之前清除ARP表:docker run --net = host --privileged --rm cap10morgan / conntrack -F 所有者(Jeff Lindsay)告诉我他们正在使用内置的修复程序重新分配整个容器,不幸的是没有时间表。 资料来源: https : //github.com/progrium/docker-co ...
  • 感谢大家,我能够弄清楚这个问题。 我的一个节点运行2.4.0,另一个运行2.4.1。 这种方式重新路由无法正常工作。 curl -XPOST -d '{ "commands" : [ { > "allocate" : { > "index" : ".kibana", > "shard" : 0, > "node" : "proc-gts-elk01", > "allow_primary":true > } > } ] }' http: ...
  • 感谢您的回复,问题是所有节点上的版本不一样,现有成员有2.3.4,而新成员有2.3.3。 通过这样做我发现了这个: POST _cluster/reroute?explain { "commands": [ { "move" : { "index" : "event4", "shard" : 0, "from_node" : "Toad", "to_node" : "Amelia Voght" ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)