首页 \ 问答 \ Android自定义LinearLayout没有出现(Android custom LinearLayout not appearing)

Android自定义LinearLayout没有出现(Android custom LinearLayout not appearing)

我在创建自定义LinearLayout时遇到问题

我在xml中定义了我的自定义布局,如下所示

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">

<TextView
    android:id="@+id/textViewIcon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="48sp"
    android:text="abc" />

<TextView
    android:id="@+id/textViewMessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="24sp"
    android:text="abc" />

<Button
    android:id="@+id/btnAction"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="30sp" />
</LinearLayout>

然后我在attrs.xml中定义了一些属性

 <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <declare-styleable name="CustomEmptyListView">
        <attr name="visualIcon" format="string"/>
        <attr name="message" format="string"/>
        <attr name="textColor" format="color"/>
        <attr name="iconColor" format="color"/>
        <attr name="buttonColor" format="color"/>
        <attr name="buttonVisibility" format="boolean" />
        <attr name="buttonText" format="string" />
    </declare-styleable>
    </resources>

这是我的自定义类的代码

public class CustomEmptyListView extends LinearLayout {
    private TextView txtIcon;
    private TextView txtMessage;
    private Button btnAction;

    public CustomEmptyListView(Context context, AttributeSet attrs) {
        super(context, attrs);


    }

    public CustomEmptyListView(Context context) {
        super(context);
        LayoutInflater.from(context).inflate(R.layout.empty_listview, this);
    }

    public CustomEmptyListView(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs);
        initViews(context, attrs);
    }


    private void initViews(Context context, AttributeSet attrs) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomEmptyListView, 0, 0);
        String iconText = a.getString(R.styleable.CustomEmptyListView_visualIcon);
        String message = a.getString(R.styleable.CustomEmptyListView_message);
        int buttonColor = a.getColor(R.styleable.CustomEmptyListView_buttonColor, ContextCompat.getColor(context,R.color.blueGreen));
        int textColor = a.getColor(R.styleable.CustomEmptyListView_textColor, ContextCompat.getColor(context,R.color.textCard));
        int iconColor = a.getColor(R.styleable.CustomEmptyListView_textColor, ContextCompat.getColor(context,R.color.light_grey));
        boolean btnVisible = a.getBoolean(R.styleable.CustomEmptyListView_buttonVisibility,true);
        String buttonText = a.getString(R.styleable.CustomEmptyListView_buttonText);
        a.recycle();

        LayoutInflater.from(getContext()).inflate(
                R.layout.empty_listview, this);

        txtIcon = (TextView)findViewById(R.id.textViewIcon);
        txtIcon.setText(iconText);
        txtIcon.setTextColor(iconColor);

        txtMessage = (TextView)findViewById(R.id.textViewMessage);
        txtMessage.setText(message);
        txtMessage.setTextColor(textColor);

        btnAction = (Button)findViewById(R.id.btnAction);
        btnAction.setText(buttonText);
        btnAction.setBackgroundColor(buttonColor);
        btnAction.setTextColor(ContextCompat.getColor(context,R.color.white));
        if(btnVisible){
            btnAction.setVisibility(View.GONE);
        }else{
            btnAction.setVisibility(View.VISIBLE);
        }
    }
}

并将其添加到我的布局XML文件如下

<com.package.views.CustomEmptyListView
        android:id="@+id/emptyListView"
        android:visibility="visible"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        custom:message="@string/no_hay_tareas_registradas"
        custom:visualIcon="@string/icon_tasks"
        android:layout_centerInParent="true"
        custom:buttonText="@string/anadir_tarea">

    </com.package.views.CustomEmptyListView>

在我的xml编辑器中,我只能看到一个0宽度和高度的组件,而不是在运行时显示。 我做错了什么? 先谢谢你!


I'm facing problems when creating custom LinearLayout

I have defined my custom layout in xml as follows

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">

<TextView
    android:id="@+id/textViewIcon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="48sp"
    android:text="abc" />

<TextView
    android:id="@+id/textViewMessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="24sp"
    android:text="abc" />

<Button
    android:id="@+id/btnAction"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="30sp" />
</LinearLayout>

Then I defined some attributes in attrs.xml

 <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <declare-styleable name="CustomEmptyListView">
        <attr name="visualIcon" format="string"/>
        <attr name="message" format="string"/>
        <attr name="textColor" format="color"/>
        <attr name="iconColor" format="color"/>
        <attr name="buttonColor" format="color"/>
        <attr name="buttonVisibility" format="boolean" />
        <attr name="buttonText" format="string" />
    </declare-styleable>
    </resources>

Here is the code for my custom class

public class CustomEmptyListView extends LinearLayout {
    private TextView txtIcon;
    private TextView txtMessage;
    private Button btnAction;

    public CustomEmptyListView(Context context, AttributeSet attrs) {
        super(context, attrs);


    }

    public CustomEmptyListView(Context context) {
        super(context);
        LayoutInflater.from(context).inflate(R.layout.empty_listview, this);
    }

    public CustomEmptyListView(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs);
        initViews(context, attrs);
    }


    private void initViews(Context context, AttributeSet attrs) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomEmptyListView, 0, 0);
        String iconText = a.getString(R.styleable.CustomEmptyListView_visualIcon);
        String message = a.getString(R.styleable.CustomEmptyListView_message);
        int buttonColor = a.getColor(R.styleable.CustomEmptyListView_buttonColor, ContextCompat.getColor(context,R.color.blueGreen));
        int textColor = a.getColor(R.styleable.CustomEmptyListView_textColor, ContextCompat.getColor(context,R.color.textCard));
        int iconColor = a.getColor(R.styleable.CustomEmptyListView_textColor, ContextCompat.getColor(context,R.color.light_grey));
        boolean btnVisible = a.getBoolean(R.styleable.CustomEmptyListView_buttonVisibility,true);
        String buttonText = a.getString(R.styleable.CustomEmptyListView_buttonText);
        a.recycle();

        LayoutInflater.from(getContext()).inflate(
                R.layout.empty_listview, this);

        txtIcon = (TextView)findViewById(R.id.textViewIcon);
        txtIcon.setText(iconText);
        txtIcon.setTextColor(iconColor);

        txtMessage = (TextView)findViewById(R.id.textViewMessage);
        txtMessage.setText(message);
        txtMessage.setTextColor(textColor);

        btnAction = (Button)findViewById(R.id.btnAction);
        btnAction.setText(buttonText);
        btnAction.setBackgroundColor(buttonColor);
        btnAction.setTextColor(ContextCompat.getColor(context,R.color.white));
        if(btnVisible){
            btnAction.setVisibility(View.GONE);
        }else{
            btnAction.setVisibility(View.VISIBLE);
        }
    }
}

And after adding it to my layout xml file as follows

<com.package.views.CustomEmptyListView
        android:id="@+id/emptyListView"
        android:visibility="visible"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        custom:message="@string/no_hay_tareas_registradas"
        custom:visualIcon="@string/icon_tasks"
        android:layout_centerInParent="true"
        custom:buttonText="@string/anadir_tarea">

    </com.package.views.CustomEmptyListView>

In my xml editor I only can see a 0 width and height component and nothin shows on runtime. What I'm doing wrong? Thank you in advance!


原文:https://stackoverflow.com/questions/40290653
更新时间:2022-06-17 17:06

最满意答案

此链接可以提供帮助: http//www.awseibert.net/how-to/redirecting-canonical-names-in-iis-7

您是否也将macton.com添加到您的网站绑定中?


This link can help: http://www.awseibert.net/how-to/redirecting-canonical-names-in-iis-7

Have you also added macton.com to the binding of your website?

相关问答

更多
  • 1:如果有301的话,我认为没有必要使用规范标签。 让我们想象一下你将URL从/q/111/hello-world更改为/q/111/foobar的场景。 引擎不会假设两者是平等的,除非他们访问原始URL并在其上指向/q/111/foobar的规范标签(它不会,因为它现在是301,切断页面之间关系的任何证据)。 2:我会直接做这件事。 定义一个非唯一的slug字段,并与详细信息视图中的捕获网址进行比较。 # models class MyModel(models.Model): # ... ...
  • 尝试这个: RewriteEngine On RewriteCond %{HTTPS}s ^on(s)|off RewriteCond http%1://%{HTTP_HOST}%{REQUEST_URI} ^(.*?)/es/(.*)$ [NC] RewriteRule .* - [E=CANONICAL:%1/en/%2,NE,S=1] RewriteCond %{HTTPS}s ^on(s)|off RewriteRule .* - [E=CA ...
  • 我不确定,我的问题是对的。 看来,您当前的设置依赖于那些GET参数(如mysite.com?page=2)。 如果您不想更改此设置,则必须进一步使用这些参数。 不过,这样做没有问题。 您的用户不必使用或查看它们。 要仅发布“新样式网址”,您可以在网络服务器中设置网址重定向。 这会将新样式的URL更改为旧样式的URL。 问题是301.如果用户请求旧样式URL,它也将被Web服务器接受。 拒绝请求301错误似乎很难实现。 为了解决这个问题,我想你必须改变你的参数方案。 您的网站可能仍然依赖于GET参数 - 但它 ...
  • 对于www.example.com/signup选择此规则是因为首先出现 Redirect permanent / https://www.example.com/ 而https://www.example.com/signup不存在 请参阅Apache文档https://httpd.apache.org/docs/current/mod/mod_alias.html 其次,别名和重定向按照它们在配置文件中出现的顺序进行处理,第一个匹配优先 尝试改变顺序 Serv ...
  • 这不需要设置它。 你可以直接通过地址栏。 如果你想通过链接,那么只需要为此设置规范。 That is not required to set it. you can directly go through address bar. if you want to go through link then only you need to set canonical for that.
  • gerrit.canonicalWebUrl与httpd.port配置httpd.port 。 如果您使用代理服务器(例如nginx或apache)将端口80或443(网络服务器)转发到端口8080(gerrit),这是有意义的 您必须编辑gerrit.config并将canonicalWebUrl行调整为它应该的主机名。 你应该能够运行git config -f ~/gerrit_folder/etc/gerrit.config --add gerrit.canonicalWebUrl "http://g ...
  • 您实际上并没有将规范网址传递给Google Analytics - 因为您需要一个“虚拟网址”,方法是将您想要的值作为第二个参数传递给网页浏览调用: [...] _gaq.push(['_trackPageview', ]); [...] You are not actually passing you canonical url to Google Analytics - for that you need a "virtual url", by passing ...
  • 您需要匹配空白,而不是URL编码的%20 。 URL在通过重写引擎发送之前被解码。 RewriteRule ^white-space\ -here(.*)$ http://abc.com/no-white-space-here$1 [R=301] You need to match against the whitespace, and not the URL encoded %20. The URL gets decoded before being sent through the rewrite e ...
  • 看看这里。 http://www.seo-consultant-services.co.uk/301-redirects-www-non-www-canonical-problems.html Have a look here. http://www.seo-consultant-services.co.uk/301-redirects-www-non-www-canonical-problems.html
  • 此链接可以提供帮助: http : //www.awseibert.net/how-to/redirecting-canonical-names-in-iis-7 您是否也将macton.com添加到您的网站绑定中? This link can help: http://www.awseibert.net/how-to/redirecting-canonical-names-in-iis-7 Have you also added macton.com to the binding of your webs ...

相关文章

更多

最新问答

更多
  • 您如何使用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)