Android TextView 의 주마등 효과 구현 방법
코드 구현
TextView 는 경마등 기능 을 가지 고 있 으 며,ellipsize 속성 을 marquee 로 설정 하면 됩 니 다.단,TextView 가 선 택 된 상태 에 있어 야 효과 가 있다 는 전제 가 있 습 니 다.이 를 보면 자 연 스 럽 게 컨트롤 을 사용자 정의 하여 다음 코드 를 작성 합 니 다.
public class MarqueeTextView extends TextView {
public MarqueeTextView(Context con) {
super(con);
}
public MarqueeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarqueeTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean isFocused() {
// TODO Auto-generated method stub
if(getEditableText().equals(TruncateAt.MARQUEE)){
return true;
}
return super.isFocused();
}
}
isFocused 방법 을 다시 쓰 고 판단 합 니 다.marqueen 속성 을 설정 해 야 선택 상 태 를 유지 합 니 다.그렇지 않 으 면 일반 TextView 와 같 습 니 다.다음은 바로 사용 할 수 있 습 니 다.레이아웃 을 보 세 요.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/titlebar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#39ac69" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#ffffff"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="@+id/home_location_iv"
android:layout_width="25dp"
android:layout_height="27dp"
android:layout_marginLeft="10dp"
android:scaleType="fitXY"
android:src="@drawable/icon_place" />
<com.lxj.marqueetextview.MarqueeTextView
android:id="@+id/home_location_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text=" ..."
android:textColor="#39ac69"
android:textSize="18sp" />
<ImageView
android:id="@+id/home_search_iv"
android:layout_width="25dp"
android:layout_height="27dp"
android:layout_marginRight="10dp"
android:scaleType="fitXY"
android:src="@drawable/icon_place" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
두 개의 ellipsize 속성 을'marquee'로 설정 해 야 합 니 다.줄 의 속성 인 singleLine 은 true 로 설정 해 야 합 니 다.이로써 TextView 의 주마등 효과 가 이 루어 졌 다.본 고 는 여러분 들 이 안 드 로 이 드 소프트웨어 프로 그래 밍 을 배 우 는 데 도움 이 되 기 를 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.