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
最满意答案
此链接可以提供帮助: 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 ... -
ASP.NET MVC:从查询字符串参数重定向到规范网址(ASP.NET MVC: Redirect from query string params to a canonical url)[2023-08-02]
我不确定,我的问题是对的。 看来,您当前的设置依赖于那些GET参数(如mysite.com?page=2)。 如果您不想更改此设置,则必须进一步使用这些参数。 不过,这样做没有问题。 您的用户不必使用或查看它们。 要仅发布“新样式网址”,您可以在网络服务器中设置网址重定向。 这会将新样式的URL更改为旧样式的URL。 问题是301.如果用户请求旧样式URL,它也将被Web服务器接受。 拒绝请求301错误似乎很难实现。 为了解决这个问题,我想你必须改变你的参数方案。 您的网站可能仍然依赖于GET参数 - 但它 ... -
重定向网址无效(Redirect URL not working)[2024-03-25]
对于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 ... -
页面链接的规范网址(canonical url for page link)[2022-08-23]
这不需要设置它。 你可以直接通过地址栏。 如果你想通过链接,那么只需要为此设置规范。 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 ...
-
如何使用%重定向网址?(How to redirect URL with %?)[2023-11-03]
您需要匹配空白,而不是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 ... -
将URL重写为规范?(Rewrite URL to canonical?)[2024-02-15]
看看这里。 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 ...