課程
/移動開發
/Android
/Android攻城獅的第一門課(入門篇)
為啥我把TextView換成com.immo.marqueetextview.MarqeeText之后布局全部變黑了。。。
2017-03-13
源自:Android攻城獅的第一門課(入門篇) 7-1
正在回答
這樣子
ziom
紅色區域全黑了
//新定義的類
package com.immo.marqueetextview;
import android.content.Context;
import android.util.AttributeSet;
import android.view.TextureView;
public class MarqeeText extends TextureView{
public MarqeeText(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MarqeeText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
public MarqeeText(Context context, AttributeSet attrs) {
super(context, attrs);
@Override
public boolean isFocused() {
// TODO Auto-generated method stub
return true;
//xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:id="@+id/container"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? tools:context=".MainActivity"
? ? tools:ignore="MergeRootFrame" >
? ? <com.immo.marqueetextview.MarqeeText
? ? ? ? android:id="@+id/textView1"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:singleLine="true"
? ? ? ? android:ellipsize="marquee"
? ? ? ? android:focusable="true"
? ? ? ? android:focusableInTouchMode="true"
? ? ? ? android:text="@string/TextView" />
? ? ? ? android:layout_alignParentLeft="true"
? ? ? ? android:layout_alignParentTop="true"
? ??
</RelativeLayout>
//main
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
慕粉1043563131 提問者 回復 ziom
ziom 回復 慕粉1043563131 提問者
代碼貼出來看看
慕粉1043563131 提問者
舉報
想快速掌握Android應用開發基礎,選擇學習這門課程就對了。
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-03-15
2017-03-15
2017-03-15
//新定義的類
package com.immo.marqueetextview;
import android.content.Context;
import android.util.AttributeSet;
import android.view.TextureView;
public class MarqeeText extends TextureView{
public MarqeeText(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MarqeeText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MarqeeText(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
public boolean isFocused() {
// TODO Auto-generated method stub
return true;
}
}
//xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? xmlns:tools="http://schemas.android.com/tools"
? ? android:id="@+id/container"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? tools:context=".MainActivity"
? ? tools:ignore="MergeRootFrame" >
? ? <com.immo.marqueetextview.MarqeeText
? ? ? ? android:id="@+id/textView1"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:singleLine="true"
? ? ? ? android:ellipsize="marquee"
? ? ? ? android:focusable="true"
? ? ? ? android:focusableInTouchMode="true"
? ? ? ? android:text="@string/TextView" />
? ? <com.immo.marqueetextview.MarqeeText
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:layout_alignParentLeft="true"
? ? ? ? android:layout_alignParentTop="true"
? ? ? ? android:ellipsize="marquee"
? ? ? ? android:focusable="true"
? ? ? ? android:focusableInTouchMode="true"
? ? ? ? android:singleLine="true"
? ? ? ? android:text="@string/TextView" />
? ??
</RelativeLayout>
//main
package com.immo.marqueetextview;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
2017-03-14
代碼貼出來看看