I would like to implement this file in Android Studio
just go to import or have to import a specific file.
I would like to implement this file in Android Studio
just go to import or have to import a specific file.
I applied here in this case and it looks like this: first I added the dependency in the gradle (build.gradle (Module app)) as described in the "README"
compile 'me.grantland:autofittextview:0.2.+'
Then I took the sample from the sample folder:
XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="input_hi"
android:singleLine="true"
android:text="There's a lady who's sure all that glitters is gold
And she's buying a stairway to heaven" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="label_normal" />
<TextView
android:id="@+id/output"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="example"
android:textSize="50sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="label_autofit" />
<me.grantland.widget.AutofitTextView
android:id="@+id/output_autofit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="true"
android:text="example"
android:textSize="50sp"
autofit:minTextSize="8sp" />
</LinearLayout>
and MainActivity:
public class MainActivity extends Activity {
private TextView mOutput, mAutofitOutput;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mOutput = (TextView)findViewById(R.id.output);
mAutofitOutput = (TextView)findViewById(R.id.output_autofit);
((EditText)findViewById(R.id.input)).addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
// do nothing
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
mOutput.setText(charSequence);
mAutofitOutput.setText(charSequence);
}
@Override
public void afterTextChanged(Editable editable) {
// do nothing
}
});
}
}
and it looks like this: The first is normal and underneath with autofit