How to implement a github file in Android Studio?

Asked

Viewed 488 times

0

I would like to implement that file in the Android Studio just go in the import or have to import a specific file.

1 answer

1

I applied here in this case and it was like this: first added the dependency on Gradle(build.Gradle(Module app)), as described in the "README"

compile 'me.grantland:autofittextview:0.2.+'

then I took the sample folder example:

the 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 was like this: The first is normal and downstairs with autofit

O primeiro esta normal e embaixo com autofit

  • but how you imported to your project in Android Studio?

  • So, I did not import anything, I opened the codes directly on github when you add the line in Gradle and give a "Sync" it already adds the dependencies necessary for you to use autofit, and here it worked as shown in the image.

  • You opened the example I understood but How to import to another project this is the doubt.

  • I thought you just wanted this functionality of the github project working on your project, so it would be like I showed you by my project.

  • in case just copy this code inside the project ?

  • Yes, that’s what I did to test, I took a look at it yesterday and there’s another layout there in the github project but I didn’t put it in my example, I did the test only with xml and the main Activity, as I showed, to see it working since I didn’t know it either. And don’t forget to add Compile to your project’s Gradle

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.